• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmobiletools

obeximpl.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    Copyright (C) 2007
00003    by Marco Gulino <marco@kmobiletools.org>
00004    Kevin Ottens <ervin ipsquad net>
00005    Marcin Przylucki <marcin.przylucki@kdemail.net>
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the
00018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020  ***************************************************************************/
00021 
00022 #include "obeximpl.h"
00023 
00024 #include <kdebug.h>
00025 #include <kglobalsettings.h>
00026 #include <kstandarddirs.h>
00027 #include <kdesktopfile.h>
00028 
00029 #include <qapplication.h>
00030 #include <qeventloop.h>
00031 #include <qdir.h>
00032 //Added by qt3to4:
00033 #include <Q3ValueList>
00034 #include <kmimetype.h>
00035 
00036 #include <sys/stat.h>
00037 
00038 #include "kmobiletools_cfg.h"
00039 #include "devicesconfig.h"
00040 
00041 
00042 #include "obexwrapper.h"
00043 
00044 OBEXImpl::OBEXImpl() : QObject()
00045     , obexWrapper(0)
00046 {
00047     KGlobal::dirs()->addResourceType("obex_entries",KStandardDirs::kde_default("data") + "obexview");
00048     obexWrapper = new OBEXWrapper();
00049 }
00050 
00051 void OBEXImpl::setHostConfig(const QString &device, int port, transport i_transport )
00052 {
00053     obexWrapper->disconnectClient();
00054     kDebug() <<"OBEXImpl::setHostConfig(" << device <<"," << port <<"," << (int) i_transport <<")";
00055     kDebug() <<"Using transport" << i_transport;
00056     obexWrapper->setupParameters(i_transport, port, device, UUID_FBS, sizeof(UUID_FBS) , 1, 1);
00057     obexWrapper->connectClient();
00058 }
00059 
00060 bool OBEXImpl::listDirectory(const KUrl &url, Q3ValueList<KIO::UDSEntry> &list)
00061 {
00062     kDebug() <<"OBEXImpl::listDirectory:" << url;
00063     kDebug() <<"OBEXImpl::listDirectory---- directory path only:" << url.path();
00064 
00065     QString neededPath = url.path();
00066     
00067     /* Getting file list from device to "OBEXWrapper::files" class member*/
00068     if ( !obexWrapper->fetchFileList( neededPath )) return false;
00069 
00070     Q3ValueList<stat_entry_t> obexfiles = obexWrapper->getFiles();
00071     Q3ValueListIterator<stat_entry_t> fileInfo;
00072 
00073     for(fileInfo=obexfiles.begin(); fileInfo!=obexfiles.end(); ++fileInfo)
00074     {
00075         KIO::UDSEntry entry;
00076         createEntry( entry, url, *fileInfo);
00077         list.append(entry);
00078     }
00079 
00080     return true;
00081 }
00082 
00083 
00084 static void addAtom(KIO::UDSEntry &entry, unsigned int ID, long l,
00085                     const QString &s = QString() )
00086 {
00087     KIO::UDSAtom atom;
00088     atom.m_uds = ID;
00089     atom.m_long = l;
00090     atom.m_str = s;
00091     entry.append(atom);
00092 }
00093 
00094 
00095 void OBEXImpl::createTopLevelEntry(KIO::UDSEntry &entry) const
00096 {
00097     entry.clear();
00098     addAtom(entry, KIO::UDSEntry::UDS_NAME, 0, ".");
00099     addAtom(entry, KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
00100     addAtom(entry, KIO::UDSEntry::UDS_ACCESS, 0777);
00101     addAtom(entry, KIO::UDSEntry::UDS_MIME_TYPE, 0, "inode/directory");
00102     addAtom(entry, KIO::UDSEntry::UDS_ICON_NAME, 0, "obex");
00103     addAtom(entry, KIO::UDSEntry::UDS_USER, 0, "root");
00104     addAtom(entry, KIO::UDSEntry::UDS_GROUP, 0, "root");
00105 }
00106 
00107 void OBEXImpl::createEntry(KIO::UDSEntry &entry,
00108                         const KUrl &url,
00109                         stat_entry_t &file)
00110 {
00111     QString filename=file.name;
00112     
00113     QString directory = /*url.host() +*/ url.path(+1);
00114     
00115     KMimeType mimetype=(* KMimeType::findByURL( directory+filename, file.mode, false,  true));
00116     KDesktopFile desktop(directory+file.name, true);
00117     kDebug() <<"KDesktopFile::" << desktop.fileName();
00118 
00119     entry.clear();
00120 
00121     addAtom(entry, KIO::UDSEntry::UDS_NAME, 0, file.name);
00122     addAtom(entry, KIO::UDSEntry::UDS_SIZE, file.size);
00123     //  addAtom(entry, KIO::UDSEntry::UDS_URL, 0, "obex:/"+directory + filename);
00124     //  kDebug() <<"*******debug UDSEntry::UDS_URL: obex:/" << directory << filename;
00125     //  addAtom(entry, KIO::UDSEntry::UDS_FILE_TYPE, (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH) );
00126     addAtom(entry, KIO::UDSEntry::UDS_FILE_TYPE, file.mode );
00127     addAtom(entry, KIO::UDSEntry::UDS_CREATION_TIME, file.mtime );
00128     addAtom(entry, KIO::UDSEntry::UDS_MIME_TYPE, 0, mimetype.name() );
00129 
00130     kDebug() << directory+file.name <<" mime type:" << mimetype.name() <<"; file attributes:" << file.mode;
00131 
00132     QString icon = desktop.readIcon();
00133     QString empty_icon = desktop.readEntry("EmptyIcon");
00134 
00135     if (!empty_icon.isEmpty())
00136     {
00137         KUrl url = desktop.readURL();
00138 
00139         m_lastListingEmpty = true;
00140 
00141         KIO::ListJob *job = KIO::listDir(url, KIO::HideProgressInfo, false);
00142         connect( job, SIGNAL( entries(KIO::Job *,
00143                 const KIO::UDSEntryList &) ),
00144                 this, SLOT( slotEntries(KIO::Job *,
00145                             const KIO::UDSEntryList &) ) );
00146         connect( job, SIGNAL( result(KIO::Job *) ),
00147                 this, SLOT( slotResult(KIO::Job *) ) );
00148         qApp->eventLoop()->enterLoop();
00149 
00150         if (m_lastListingEmpty) icon = empty_icon;
00151     }
00152 
00153     addAtom(entry, KIO::UDSEntry::UDS_ICON_NAME, 0, icon);
00154 }
00155 
00156 
00157 void OBEXImpl::slotEntries(KIO::Job *job, const KIO::UDSEntryList &list)
00158 {
00159     if (list.size()>0)
00160     {
00161         job->kill(true);
00162         m_lastListingEmpty = false;
00163         qApp->eventLoop()->exitLoop();
00164     }
00165 }
00166 
00167 void OBEXImpl::slotResult(KIO::Job *)
00168 {
00169     qApp->eventLoop()->exitLoop();
00170 }
00171 
00172 
00173 #include "obeximpl.moc"
00174 
00175 
00180 void OBEXImpl::fetchFilesList( const QString &path )
00181 {
00182     obexWrapper->fetchFileList( path );
00183 }
00184 
00189 int OBEXImpl::getFile(const KUrl &url)
00190 {
00191     kDebug() <<"kio_obex::getFile" << url.path();
00192     return obexWrapper->getFile( url.path());
00193     return 0;
00194 }
00195 
00200 bool OBEXImpl::statEntry(const KUrl &url, KIO::UDSEntry &entry)
00201 {
00202     kDebug() <<"Stat for" << url.path();
00203 
00204     QString neededPath = url.path().latin1();
00205     stat_entry_t* currentEntry;
00206     
00207     if( !wrapper()->connectClient() ) return false;
00208     currentEntry = obexftp_stat( wrapper()->getClient(), neededPath);
00209     if ( !currentEntry ) return false;
00210 
00211     entry.clear();
00212     createEntry( entry, url, *currentEntry );
00213 
00214     return true;
00215 }

kmobiletools

Skip menu "kmobiletools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal