-rw-r--r-- | library/alarmserver.cpp | 2 | ||||
-rw-r--r-- | library/applnk.cpp | 4 | ||||
-rw-r--r-- | library/fileselector.cpp | 2 | ||||
-rw-r--r-- | library/fontdatabase.cpp | 2 | ||||
-rw-r--r-- | library/fontmanager.cpp | 2 | ||||
-rw-r--r-- | library/global.cpp | 28 | ||||
-rw-r--r-- | library/ir.cpp | 2 | ||||
-rw-r--r-- | library/lnkproperties.cpp | 2 | ||||
-rw-r--r-- | library/network.cpp | 2 | ||||
-rw-r--r-- | library/networkinterface.cpp | 2 | ||||
-rw-r--r-- | library/password.cpp | 2 | ||||
-rw-r--r-- | library/qpedecoration_qws.cpp | 2 | ||||
-rw-r--r-- | library/tzselect.cpp | 4 |
13 files changed, 11 insertions, 45 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp index 177a0cb..02bca3d 100644 --- a/library/alarmserver.cpp +++ b/library/alarmserver.cpp @@ -1,403 +1,401 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qdir.h> #include <qfile.h> #include <qmessagebox.h> #include <qtextstream.h> #include <qpe/qpeapplication.h> #include "global.h" #include "resource.h" -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> -#endif #include "alarmserver.h" #include <qpe/timeconversion.h> #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #include <unistd.h> struct timerEventItem { time_t UTCtime; QCString channel, message; int data; bool operator==( const timerEventItem &right ) const { return ( UTCtime == right.UTCtime && channel == right.channel && message == right.message && data == right.data ); } }; class TimerReceiverObject : public QObject { public: TimerReceiverObject() { } ~TimerReceiverObject() { } void resetTimer(); void setTimerEventItem(); void deleteTimer(); protected: void timerEvent( QTimerEvent *te ); private: QString atfilename; }; TimerReceiverObject *timerEventReceiver = NULL; QList<timerEventItem> timerEventList; timerEventItem *nearestTimerEvent = NULL; // set the timer to go off on the next event in the list void setNearestTimerEvent() { nearestTimerEvent = NULL; QListIterator<timerEventItem> it( timerEventList ); if ( *it ) nearestTimerEvent = *it; for ( ; *it; ++it ) if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) nearestTimerEvent = *it; if (nearestTimerEvent) timerEventReceiver->resetTimer(); else timerEventReceiver->deleteTimer(); } //store current state to file //Simple implementation. Should run on a timer. static void saveState() { QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); if ( timerEventList.isEmpty() ) { unlink( savefilename ); return; } QFile savefile(savefilename+".new"); if ( savefile.open(IO_WriteOnly) ) { QDataStream ds( &savefile ); //save QListIterator<timerEventItem> it( timerEventList ); for ( ; *it; ++it ) { ds << it.current()->UTCtime; ds << it.current()->channel; ds << it.current()->message; ds << it.current()->data; } savefile.close(); unlink( savefilename ); QDir d; d.rename(savefilename+".new",savefilename); } } /*! Sets up the alarm server. Restoring to previous state (session management). */ void AlarmServer::initialize() { //read autosave file and put events in timerEventList QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); QFile savefile(savefilename); if ( savefile.open(IO_ReadOnly) ) { QDataStream ds( &savefile ); while ( !ds.atEnd() ) { timerEventItem *newTimerEventItem = new timerEventItem; ds >> newTimerEventItem->UTCtime; ds >> newTimerEventItem->channel; ds >> newTimerEventItem->message; ds >> newTimerEventItem->data; timerEventList.append( newTimerEventItem ); } savefile.close(); if (!timerEventReceiver) timerEventReceiver = new TimerReceiverObject; setNearestTimerEvent(); } } static const char* atdir = "/var/spool/at/"; static bool triggerAtd( bool writeHWClock = FALSE ) { QFile trigger(QString(atdir) + "trigger"); if ( trigger.open(IO_WriteOnly|IO_Raw) ) { const char* data = #ifdef QT_QWS_CUSTOM //custom atd only writes HW Clock if we write a 'W' ( writeHWClock ) ? "W\n" : #endif data = "\n"; int len = strlen(data); int total_written = trigger.writeBlock(data,len); if ( total_written != len ) { QMessageBox::critical( 0, QObject::tr( "Out of Space" ), QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) ); trigger.close(); QFile::remove( trigger.name() ); return FALSE; } return TRUE; } return FALSE; } void TimerReceiverObject::deleteTimer() { if ( !atfilename.isEmpty() ) { unlink( atfilename ); atfilename = QString::null; triggerAtd( FALSE ); } } void TimerReceiverObject::resetTimer() { const int maxsecs = 2147000; int total_written; QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); QDateTime now = QDateTime::currentDateTime(); if ( nearest < now ) nearest = now; int secs = TimeConversion::secsTo( now, nearest ); if ( secs > maxsecs ) { // too far for millisecond timing secs = maxsecs; } // System timer (needed so that we wake from deep sleep), // from the Epoch in seconds. // int at_secs = TimeConversion::toUTC(nearest); // qDebug("reset timer to %d seconds from Epoch",at_secs); QString fn = atdir + QString::number(at_secs) + "." + QString::number(getpid()); if ( fn != atfilename ) { QFile atfile(fn+".new"); if ( atfile.open(IO_WriteOnly|IO_Raw) ) { // just wake up and delete the at file QString cmd = "#!/bin/sh\nrm " + fn; total_written = atfile.writeBlock(cmd.latin1(),cmd.length()); if ( total_written != int(cmd.length()) ) { QMessageBox::critical( 0, tr("Out of Space"), tr("Unable to schedule alarm.\n" "Please free up space and try again") ); atfile.close(); QFile::remove( atfile.name() ); return; } atfile.close(); unlink( atfilename ); QDir d; d.rename(fn+".new",fn); chmod(fn.latin1(),0755); atfilename = fn; triggerAtd( FALSE ); } else { qWarning("Cannot open atd file %s",fn.latin1()); } } // Qt timers (does the actual alarm) // from now in milliseconds // qDebug("AlarmServer waiting %d seconds",secs); startTimer( 1000 * secs + 500 ); } void TimerReceiverObject::timerEvent( QTimerEvent * ) { bool needSave = FALSE; killTimers(); if (nearestTimerEvent) { if ( nearestTimerEvent->UTCtime <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { #ifndef QT_NO_COP QCopEnvelope e( nearestTimerEvent->channel, nearestTimerEvent->message ); e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) << nearestTimerEvent->data; #endif timerEventList.remove( nearestTimerEvent ); needSave = TRUE; } setNearestTimerEvent(); } else { resetTimer(); } if ( needSave ) saveState(); } /*! \class AlarmServer alarmserver.h \brief The AlarmServer class allows alarms to be scheduled and unscheduled. Applications can schedule alarms with addAlarm() and can unschedule alarms with deleteAlarm(). When the time for an alarm to go off is reached the specified \link qcop.html QCop\endlink message is sent on the specified channel (optionally with additional data). Scheduling an alarm using this class is important (rather just using a QTimer) since the machine may be asleep and needs to get woken up using the Linux kernel which implements this at the kernel level to minimize battery usage while asleep. \ingroup qtopiaemb \sa QCopEnvelope */ /*! Schedules an alarm to go off at (or soon after) time \a when. When the alarm goes off, the \link qcop.html QCop\endlink \a message will be sent to \a channel, with \a data as a parameter. If this function is called with exactly the same data as a previous call the subsequent call is ignored, so there is only ever one alarm with a given set of parameters. \sa deleteAlarm() */ void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, const QCString& message, int data) { if ( qApp->type() == QApplication::GuiServer ) { bool needSave = FALSE; // Here we are the server so either it has been directly called from // within the server or it has been sent to us from a client via QCop if (!timerEventReceiver) timerEventReceiver = new TimerReceiverObject; timerEventItem *newTimerEventItem = new timerEventItem; newTimerEventItem->UTCtime = TimeConversion::toUTC( when ); newTimerEventItem->channel = channel; newTimerEventItem->message = message; newTimerEventItem->data = data; // explore the case of already having the event in here... QListIterator<timerEventItem> it( timerEventList ); for ( ; *it; ++it ) if ( *(*it) == *newTimerEventItem ) return; // if we made it here, it is okay to add the item... timerEventList.append( newTimerEventItem ); needSave = TRUE; // quicker than using setNearestTimerEvent() if ( nearestTimerEvent ) { if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) { nearestTimerEvent = newTimerEventItem; timerEventReceiver->killTimers(); timerEventReceiver->resetTimer(); } } else { nearestTimerEvent = newTimerEventItem; timerEventReceiver->resetTimer(); } if ( needSave ) saveState(); } else { #ifndef QT_NO_COP QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); e << when << channel << message << data; #endif } } /*! Deletes previously scheduled alarms which match \a when, \a channel, \a message, and \a data. Passing null values for \a when, \a channel, or for the \link qcop.html QCop\endlink \a message, acts as a wildcard meaning "any". Similarly, passing -1 for \a data indicates "any". If there is no matching alarm, nothing happens. \sa addAlarm() */ void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) { if ( qApp->type() == QApplication::GuiServer) { bool needSave = FALSE; if ( timerEventReceiver != NULL ) { timerEventReceiver->killTimers(); // iterate over the list of events QListIterator<timerEventItem> it( timerEventList ); time_t deleteTime = TimeConversion::toUTC( when ); for ( ; *it; ++it ) { // if its a match, delete it if ( ( (*it)->UTCtime == deleteTime || when.isNull() ) && ( channel.isNull() || (*it)->channel == channel ) && ( message.isNull() || (*it)->message == message ) && ( data==-1 || (*it)->data == data ) ) { // if it's first, then we need to update the timer if ( (*it) == nearestTimerEvent ) { timerEventList.remove(*it); setNearestTimerEvent(); } else { timerEventList.remove(*it); } needSave = TRUE; } } if ( nearestTimerEvent ) timerEventReceiver->resetTimer(); } if ( needSave ) saveState(); } else { #ifndef QT_NO_COP QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); e << when << channel << message << data; #endif } } /*! Writes the system clock to the hardware clock. */ void Global::writeHWClock() { if ( !triggerAtd( TRUE ) ) { // atd not running? set it ourselves system("/sbin/hwclock --systohc"); // ##### UTC? } } diff --git a/library/applnk.cpp b/library/applnk.cpp index a56da5d..5763c62 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp @@ -1,1069 +1,1065 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_MIMEEXT #define QTOPIA_INTERNAL_PRELOADACCESS #define QTOPIA_INTERNAL_APPLNKASSIGN #include "applnk.h" #include <qpe/qpeapplication.h> #include <qpe/categories.h> #include <qpe/categoryselect.h> -#ifdef QWS #include <qpe/qcopenvelope_qws.h> -#endif #include <qpe/global.h> #include <qpe/mimetype.h> #include <qpe/config.h> #include <qpe/storage.h> #include <qpe/resource.h> #include <qdict.h> #include <qdir.h> #include <qregexp.h> -#ifdef Q_WS_QWS #include <qgfx_qws.h> -#endif #include <stdlib.h> int AppLnk::lastId = 5000; static int smallSize = 14; static int bigSize = 32; static QString safeFileName(const QString& n) { QString safename=n; safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); safename.replace(QRegExp("^[^A-Za-z]*"),""); if ( safename.isEmpty() ) safename = "_"; return safename; } static bool prepareDirectories(const QString& lf) { if ( !QFile::exists(lf) ) { // May need to create directories QFileInfo fi(lf); if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) return FALSE; } return TRUE; } class AppLnkPrivate { public: /* the size of the Pixmap */ enum Size {Normal = 0, Big }; AppLnkPrivate() { /* we want one normal and one big item */ QPixmap pix; mPixmaps.insert(0, pix ); mPixmaps.insert(1, pix); } QStringList mCatList; // always correct QArray<int> mCat; // cached value; correct if not empty QMap<int, QPixmap> mPixmaps; void updateCatListFromArray() { Categories cat( 0 ); cat.load( categoryFileName() ); mCatList = cat.labels("Document View",mCat); } void setCatArrayDirty() { mCat.resize(0); } void ensureCatArray() { if ( mCat.count() > 0 || mCatList.count()==0 ) return; Categories cat( 0 ); cat.load( categoryFileName() ); mCat.resize( mCatList.count() ); int i; QStringList::ConstIterator it; for ( i = 0, it = mCatList.begin(); it != mCatList.end(); ++it, i++ ) { bool number; int id = (*it).toInt( &number ); if ( !number ) { id = cat.id( "Document View", *it ); if ( id == 0 ) id = cat.addCategory( "Document View", *it ); } mCat[i] = id; } } }; /*! \class AppLnk applnk.h \brief The AppLnk class represents an application available on the system. Every Qtopia application \e app has a corresponding \e app.desktop file. When one of these files is read its data is stored as an AppLnk object. The AppLnk class introduces some Qtopia-specific concepts, and provides a variety of functions, as described in the following sections. \tableofcontents \target Types \section1 Types Every AppLnk object has a \e type. For applications, games and settings the type is \c Application; for documents the type is the document's MIME type. \target files-and-links \section1 Files and Links When you create an AppLnk (or more likely, a \link doclnk.html DocLnk\endlink), you don't deal directly with filenames in the filesystem. Instead you do this: \code DocLnk d; d.setType("text/plain"); d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. \endcode At this point, the file() and linkFile() are unknown. Normally this is uninteresting, and the names become automatically known, and more importantly, becomes reserved, when you ask what they are: \code QString fn = d.file(); \endcode This invents a filename, and creates the file on disk (an empty reservation file) to prevent the name being used by another application. In some circumstances, you don't want to create the file if it doesn't already exist (e.g. in the Document tab, some of the \link doclnk.html DocLnk\endlink objects represented by icons are DocLnk's created just for that view - they don't have corresponding \c .desktop files. To avoid littering empty reservation files around, we check in a few places to see whether the file really needs to exist). \section1 Functionality AppLnk objects are created by calling the constructor with the name of a \e .desktop file. The object can be checked for validity using isValid(). The following functions are used to set or retrieve information about the application: \table \header \i Get Function \i Set Function \i Short Description \row \i \l name() \i \l setName() \i application's name \row \i \l pixmap() \i \e none \i application's icon \row \i \l bigPixmap() \i \e none \i application's large icon \row \i \e none \i setIcon() \i sets the icon's filename \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees \row \i \l comment() \i \l setComment() \i text for the Details dialog \row \i \l exec() \i \l setExec() \i executable's filename \row \i \l file() \i \e none \i document's filename \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions} \row \i \l fileKnown() \i \e none \i see \link #files-and-links Files and Links\endlink above \row \i \l linkFileKnown() \i \e none \i see \link #files-and-links Files and Links\endlink above \row \i \l property() \i \l setProperty() \i any AppLnk property can be retrieved or set (if writeable) using these \endtable To save an AppLnk to disk use writeLink(). To execute the application that the AppLnk object refers to, use execute(). AppLnk's can be deleted from disk using removeLinkFile(). To remove both the link and the application's executable use removeFiles(). Icon sizes can be globally changed (but only for AppLnk objects created after the calls) with setSmallIconSize() and setBigIconSize(). \ingroup qtopiaemb */ /*! Sets the size used for small icons to \a small pixels. Only affects AppLnk objects created after the call. \sa smallIconSize() setIcon() */ void AppLnk::setSmallIconSize(int small) { smallSize = small; } /*! Returns the size used for small icons. \sa setSmallIconSize() setIcon() */ int AppLnk::smallIconSize() { return smallSize; } /*! Sets the size used for large icons to \a big pixels. Only affects AppLnk objects created after the call. \sa bigIconSize() setIcon() */ void AppLnk::setBigIconSize(int big) { bigSize = big; } /*! Returns the size used for large icons. \sa setBigIconSize() setIcon() */ int AppLnk::bigIconSize() { return bigSize; } /*! \fn QString AppLnk::name() const Returns the Name property. This is the user-visible name for the document or application, not the filename. See \link #files-and-links Files and Links\endlink. \sa setName() */ /*! \fn QString AppLnk::exec() const Returns the Exec property. This is the name of the executable program associated with the AppLnk. \sa setExec() */ /*! \fn QString AppLnk::rotation() const Returns the Rotation property. The value is 0, 90, 180 or 270 degrees. */ /*! \fn QString AppLnk::comment() const Returns the Comment property. \sa setComment() */ /*! \fn QStringList AppLnk::mimeTypes() const Returns the MimeTypes property. This is the list of MIME types that the application can view or edit. */ /*! \fn const QArray<int>& AppLnk::categories() const Returns the Categories property. See the CategoryWidget for more details. \sa setCategories() */ const QArray<int>& AppLnk::categories() const { d->ensureCatArray(); return d->mCat; } /*! \fn int AppLnk::id() const Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, this value is 0, otherwise it is a value that is unique for the duration of the current process. \sa AppLnkSet::find() */ /*! \fn bool AppLnk::isValid() const Returns TRUE if this AppLnk is valid; otherwise returns FALSE. */ /*! Creates an invalid AppLnk. \sa isValid() */ AppLnk::AppLnk() { mId = 0; d = new AppLnkPrivate(); } /*! Loads \a file (e.g. \e app.desktop) as an AppLnk. \sa writeLink() */ AppLnk::AppLnk( const QString &file ) { QStringList sl; d = new AppLnkPrivate(); if ( !file.isNull() ) { Config config( file, Config::File ); if ( config.isValid() ) { config.setGroup( "Desktop Entry" ); mName = config.readEntry( "Name", file ); mExec = config.readEntry( "Exec" ); mType = config.readEntry( "Type", QString::null ); mIconFile = config.readEntry( "Icon", QString::null ); mRotation = config.readEntry( "Rotation", "" ); mComment = config.readEntry( "Comment", QString::null ); // MIME types are case-insensitive. mMimeTypes = config.readListEntry( "MimeType", ';' ); for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) *it = (*it).lower(); mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); mLinkFile = file; mFile = config.readEntry("File", QString::null); if ( !mExec. isEmpty ( )) { mFile = QString::null; } else if ( mFile[0] != '/' ) { int slash = file.findRev('/'); if ( slash >= 0 ) { mFile = file.left(slash) + '/' + mFile; } } d->mCatList = config.readListEntry("Categories", ';'); if ( d->mCatList[0].toInt() < -1 ) { // numeric cats in file! convert to text Categories cat( 0 ); cat.load( categoryFileName() ); d->mCat.resize( d->mCatList.count() ); int i; QStringList::ConstIterator it; for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); ++it, i++ ) { bool number; int id = (*it).toInt( &number ); if ( !number ) { // convert from text id = cat.id( "Document View", *it ); if ( id == 0 ) id = cat.addCategory( "Document View", *it ); } d->mCat[i] = id; } d->updateCatListFromArray(); } } } mId = 0; } AppLnk& AppLnk::operator=(const AppLnk ©) { if ( mId ) qWarning("Deleting AppLnk that is in an AppLnkSet"); if ( d ) delete d; mName = copy.mName; /* remove for Qtopia 3.0 -zecke */ mPixmap = copy.mPixmap; mBigPixmap = copy.mBigPixmap; mExec = copy.mExec; mType = copy.mType; mRotation = copy.mRotation; mComment = copy.mComment; mFile = copy.mFile; mLinkFile = copy.mLinkFile; mIconFile = copy.mIconFile; mMimeTypes = copy.mMimeTypes; mMimeTypeIcons = copy.mMimeTypeIcons; mId = 0; d = new AppLnkPrivate(); d->mCat = copy.d->mCat; d->mCatList = copy.d->mCatList; d->mPixmaps = copy.d->mPixmaps; return *this; } /*! protected internally to share code should I document that at all? I don't know the TT style for that */ const QPixmap& AppLnk::pixmap( int pos, int size ) const { if ( d->mPixmaps[pos].isNull() ) { AppLnk* that = (AppLnk*)this; if ( mIconFile.isEmpty() ) { MimeType mt(type()); that->d->mPixmaps[pos] = mt.pixmap(); if ( that->d->mPixmaps[pos].isNull() ) that->d->mPixmaps[pos].convertFromImage( Resource::loadImage("UnknownDocument") .smoothScale( size, size ) ); return that->d->mPixmaps[pos]; } QImage unscaledIcon = Resource::loadImage( that->mIconFile ); if ( unscaledIcon.isNull() ) { qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); that->d->mPixmaps[pos].convertFromImage( Resource::loadImage("UnknownDocument") .smoothScale( size, size ) ); } else { that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); } return that->d->mPixmaps[pos]; } return d->mPixmaps[pos]; } /*! Returns a small pixmap associated with the application. \sa bigPixmap() setIcon() */ const QPixmap& AppLnk::pixmap() const { if ( d->mPixmaps[0].isNull() ) { return pixmap(AppLnkPrivate::Normal, smallSize ); } return d->mPixmaps[0]; } /*! Returns a large pixmap associated with the application. \sa pixmap() setIcon() */ const QPixmap& AppLnk::bigPixmap() const { if ( d->mPixmaps[1].isNull() ) { return pixmap( AppLnkPrivate::Big, bigSize ); } return d->mPixmaps[1]; } /*! Returns the type of the AppLnk. For applications, games and settings the type is \c Application; for documents the type is the document's MIME type. */ QString AppLnk::type() const { if ( mType.isNull() ) { AppLnk* that = (AppLnk*)this; QString f = file(); if ( !f.isNull() ) { MimeType mt(f); that->mType = mt.id(); return that->mType; } } return mType; } /*! Returns the file associated with the AppLnk. \sa exec() name() */ QString AppLnk::file() const { if ( mExec.isEmpty ( ) && mFile.isNull() ) { AppLnk* that = (AppLnk*)this; QString ext = MimeType(mType).extension(); if ( !ext.isEmpty() ) ext = "." + ext; if ( !mLinkFile.isEmpty() ) { that->mFile = mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; qDebug("mFile now == %s", mFile.latin1()); } else if ( mType.contains('/') ) { that->mFile = QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); /* * A file with the same name or a .desktop file already exists */ if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { int n=1; QString nn; while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) || QFile::exists(nn+".desktop")) n++; that->mFile = nn; } that->mLinkFile = that->mFile+".desktop"; that->mFile += ext; } prepareDirectories(that->mFile); if ( !that->mFile.isEmpty() ) { QFile f(that->mFile); if ( !f.open(IO_WriteOnly) ) that->mFile = QString::null; return that->mFile; } } return mFile; } /*! Returns the desktop file corresponding to this AppLnk. \sa file() exec() name() */ QString AppLnk::linkFile() const { if ( mLinkFile.isNull() ) { AppLnk* that = (AppLnk*)this; if ( type().contains('/') ) { StorageInfo storage; const FileSystem *fs = storage.fileSystemOf( that->mFile ); /* tmpfs + and ramfs are available too but not removable * either we fix storage or add this */ if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { that->mLinkFile = fs->path(); } else that->mLinkFile = getenv( "HOME" ); that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); /* the desktop file exists make sure we don't point to the same file */ if ( QFile::exists(that->mLinkFile+".desktop") ) { AppLnk lnk( that->mLinkFile + ".desktop" ); /* the linked is different */ if(that->file() != lnk.file() ) { int n = 1; QString nn; while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { n++; /* just to be sure */ AppLnk lnk(nn ); if (lnk.file() == that->file() ) break; } that->mLinkFile = nn; } } that->mLinkFile += ".desktop"; storeLink(); } return that->mLinkFile; } return mLinkFile; } /*! Copies \a copy. */ AppLnk::AppLnk( const AppLnk © ) { mName = copy.mName; mPixmap = copy.mPixmap; mBigPixmap = copy.mBigPixmap; mExec = copy.mExec; mType = copy.mType; mRotation = copy.mRotation; mComment = copy.mComment; mFile = copy.mFile; mLinkFile = copy.mLinkFile; mIconFile = copy.mIconFile; mMimeTypes = copy.mMimeTypes; mMimeTypeIcons = copy.mMimeTypeIcons; mId = 0; d = new AppLnkPrivate(); d->mCat = copy.d->mCat; d->mCatList = copy.d->mCatList; d->mPixmaps = copy.d->mPixmaps; } /*! Destroys the AppLnk. Note that if the AppLnk is currently a member of an AppLnkSet, this will produce a run-time warning. \sa AppLnkSet::add() AppLnkSet::remove() */ AppLnk::~AppLnk() { if ( mId ) qWarning("Deleting AppLnk that is in an AppLnkSet"); if ( d ) delete d; } /*! \overload Executes the application associated with this AppLnk. \sa exec() */ void AppLnk::execute() const { execute(QStringList()); } /*! Executes the application associated with this AppLnk, with \a args as arguments. \sa exec() */ void AppLnk::execute(const QStringList& args) const { #ifdef Q_WS_QWS if ( !mRotation.isEmpty() ) { // ######## this will only work in the server int rot = QPEApplication::defaultRotation(); rot = (rot+mRotation.toInt())%360; QCString old = getenv("QWS_DISPLAY"); setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); invoke(args); setenv("QWS_DISPLAY", old.data(), 1); } else #endif invoke(args); } /*! Invokes the application associated with this AppLnk, with \a args as arguments. Rotation is not taken into account by this function, so you should not call it directly. \sa execute() */ void AppLnk::invoke(const QStringList& args) const { Global::execute( exec(), args[0] ); } /*! Sets the Exec property to \a exec. \sa exec() name() */ void AppLnk::setExec( const QString& exec ) { mExec = exec; } #if 0 // this was inlined for better BC /*! Sets the Rotation property to \a rot. \sa rotation() */ void AppLnk::setRotation ( const QString &rot ) { mRotation = rot; } #endif /*! Sets the Name property to \a docname. \sa name() */ void AppLnk::setName( const QString& docname ) { mName = docname; } /*! Sets the File property to \a filename. \sa file() name() */ void AppLnk::setFile( const QString& filename ) { mFile = filename; } /*! Sets the LinkFile property to \a filename. \sa linkFile() */ void AppLnk::setLinkFile( const QString& filename ) { mLinkFile = filename; } /*! Sets the Comment property to \a comment. This text is displayed in the 'Details Dialog', for example if the user uses the 'press-and-hold' gesture. \sa comment() */ void AppLnk::setComment( const QString& comment ) { mComment = comment; } /*! Sets the Type property to \a type. For applications, games and settings the type should be \c Application; for documents the type should be the document's MIME type. \sa type() */ void AppLnk::setType( const QString& type ) { mType = type; } /*! \fn QString AppLnk::icon() const Returns the Icon property. \sa setIcon() */ /*! Sets the Icon property to \a iconname. This is the filename from which the pixmap() and bigPixmap() are obtained. \sa icon() setSmallIconSize() setBigIconSize() */ void AppLnk::setIcon( const QString& iconname ) { mIconFile = iconname; QImage unscaledIcon = Resource::loadImage( mIconFile ); d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); } /*! Sets the Categories property to \a c. See the CategoryWidget for more details. \sa categories() */ void AppLnk::setCategories( const QArray<int>& c ) { d->mCat = c; d->updateCatListFromArray(); } /*! \fn QStringList AppLnk::mimeTypeIcons() const Returns the MimeTypeIcons property of the AppLnk. */ /*! Attempts to ensure that the link file for this AppLnk exists, including creating any required directories. Returns TRUE if successful; otherwise returns FALSE. You should not need to use this function. */ bool AppLnk::ensureLinkExists() const { QString lf = linkFile(); return prepareDirectories(lf); } /*! Commits the AppLnk to disk. Returns TRUE if the operation succeeded; otherwise returns FALSE. In addition, the "linkChanged(QString)" message is sent to the "QPE/System" \link qcop.html QCop\endlink channel. */ bool AppLnk::writeLink() const { // Only re-writes settable parts QString lf = linkFile(); if ( !ensureLinkExists() ) return FALSE; storeLink(); return TRUE; } /*! \internal */ void AppLnk::storeLink() const { Config config( mLinkFile, Config::File ); config.setGroup("Desktop Entry"); config.writeEntry("Name",mName); if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); config.writeEntry("Type",type()); if(!rotation().isEmpty()) config.writeEntry("Rotation",rotation()); else config.removeEntry("Rotation"); if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); QString f = file(); int i = 0; while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) i++; while ( i && f[i] != '/' ) i--; // simple case where in the same directory if ( mLinkFile.find( '/', i + 1 ) < 0 ) f = f.mid(i+1); // ### could do relative ie ../../otherDocs/file.doc config.writeEntry("File",f); config.writeEntry( "Categories", d->mCatList, ';' ); #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "linkChanged(QString)"); e << mLinkFile; #endif } /*! Sets the property named \a key to \a value. \sa property() */ void AppLnk::setProperty(const QString& key, const QString& value) { if ( ensureLinkExists() ) { Config cfg(linkFile(), Config::File); cfg.writeEntry(key,value); } } /*! Returns the property named \a key. \sa setProperty() */ QString AppLnk::property(const QString& key) const { QString lf = linkFile(); if ( !QFile::exists(lf) ) return QString::null; Config cfg(lf, Config::File); return cfg.readEntry(key); } bool AppLnk::isPreloaded() const { // Preload information is stored in the Launcher config in v1.5. Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps",','); if (apps.contains(exec())) return true; return false; } void AppLnk::setPreloaded(bool yesNo) { // Preload information is stored in the Launcher config in v1.5. Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps", ','); if (apps.contains(exec()) && !yesNo) apps.remove(exec()); else if (yesNo && !apps.contains(exec())) apps.append(exec()); cfg.writeEntry("Apps", apps, ','); } /*! Deletes both the linkFile() and the file() associated with this AppLnk. \sa removeLinkFile() */ void AppLnk::removeFiles() { bool valid = isValid(); if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { if ( QFile::remove(file()) ) { #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "linkChanged(QString)"); if ( linkFileKnown() ) e << linkFile(); else e << file(); #endif } else if ( valid ) { // restore link writeLink(); } } } /*! Deletes the linkFile(), leaving any file() untouched. \sa removeFiles() */ void AppLnk::removeLinkFile() { if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "linkChanged(QString)"); e << linkFile(); #endif } } class AppLnkSetPrivate { public: AppLnkSetPrivate() { typPix.setAutoDelete(TRUE); typPixBig.setAutoDelete(TRUE); typName.setAutoDelete(TRUE); } QDict<QPixmap> typPix; QDict<QPixmap> typPixBig; QDict<QString> typName; }; /*! \class AppLnkSet applnk.h \brief The AppLnkSet class is a set of AppLnk objects. */ /*! \fn QStringList AppLnkSet::types() const Returns the list of \link applnk.html#Types types\endlink in the set. For applications, games and settings the type is \c Application; for documents the type is the document's MIME type. \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() */ /*! \fn const QList<AppLnk>& AppLnkSet::children() const Returns the members of the set. */ /*! Constructs an empty AppLnkSet. */ AppLnkSet::AppLnkSet() : d(new AppLnkSetPrivate) { } /*! Constructs an AppLnkSet that contains AppLnk objects representing all the files in the given \a directory (and any subdirectories recursively). \omit The directories may contain ".directory" files which override any AppLnk::type() values for AppLnk objects found in the directory. This allows simple localization of application types. \endomit */ AppLnkSet::AppLnkSet( const QString &directory ) : d(new AppLnkSetPrivate) { QDir dir( directory ); mFile = directory; findChildren(directory,QString::null,QString::null); } /*! Detaches all AppLnk objects from the set. The set become empty and the caller becomes responsible for deleting the AppLnk objects. */ void AppLnkSet::detachChildren() { QListIterator<AppLnk> it( mApps ); for ( ; it.current(); ) { AppLnk* a = *it; ++it; a->mId = 0; } mApps.clear(); } /*! Destroys the set, deleting all the AppLnk objects it contains. \sa detachChildren() */ AppLnkSet::~AppLnkSet() { QListIterator<AppLnk> it( mApps ); for ( ; it.current(); ) { AppLnk* a = *it; ++it; a->mId = 0; delete a; } delete d; } void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) { depth++; if ( depth > 10 ) return; QDir dir( dr ); QString typNameLocal = typName; diff --git a/library/fileselector.cpp b/library/fileselector.cpp index 052a29e..4039243 100644 --- a/library/fileselector.cpp +++ b/library/fileselector.cpp @@ -1,583 +1,581 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT // have this class. #define QTOPIA_INTERNAL_FSLP #include "fileselector.h" #include "fileselector_p.h" #include "global.h" #include "resource.h" #include "config.h" #include "applnk.h" #include "storage.h" #include "qpemenubar.h" -#ifdef QWS #include <qcopchannel_qws.h> -#endif #include "lnkproperties.h" #include "applnk.h" #include <qpe/qpeapplication.h> #include "categorymenu.h" #include "categoryselect.h" #include "mimetype.h" #include <qpe/categories.h> #include <stdlib.h> #include <qdir.h> #include <qwidget.h> #include <qpopupmenu.h> #include <qtoolbutton.h> #include <qpushbutton.h> #include <qheader.h> #include <qtooltip.h> #include <qwhatsthis.h> class TypeCombo : public QComboBox { Q_OBJECT public: TypeCombo( QWidget *parent, const char *name=0 ) : QComboBox( parent, name ) { connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) ); } void reread( DocLnkSet &files, const QString &filter ); signals: void selected( const QString & ); protected slots: void selectType( int idx ) { emit selected( typelist[idx] ); } protected: QStringList typelist; QString prev; }; void TypeCombo::reread( DocLnkSet &files, const QString &filter ) { typelist.clear(); QStringList filters = QStringList::split( ';', filter ); int pos = filter.find( '/' ); //### do for each filter if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) { typelist.append( filter ); clear(); QString minor = filter.mid( pos+1 ); minor[0] = minor[0].upper(); insertItem( tr("%1 files").arg(minor) ); setCurrentItem(0); setEnabled( FALSE ); return; } QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if ( !typelist.contains( (*dit)->type() ) ) typelist.append( (*dit)->type() ); } QStringList types; QStringList::ConstIterator it; for (it = typelist.begin(); it!=typelist.end(); ++it) { QString t = *it; if ( t.left(12) == "application/" ) { MimeType mt(t); const AppLnk* app = mt.application(); if ( app ) t = app->name(); else t = t.mid(12); } else { QString major, minor; int pos = t.find( '/' ); if ( pos >= 0 ) { major = t.left( pos ); minor = t.mid( pos+1 ); } if ( minor.find( "x-" ) == 0 ) minor = minor.mid( 2 ); minor[0] = minor[0].upper(); major[0] = major[0].upper(); if ( filters.count() > 1 ) t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major); else t = minor; } types += tr("%1 files").arg(t); } for (it = filters.begin(); it!=filters.end(); ++it) { typelist.append( *it ); int pos = (*it).find( '/' ); if ( pos >= 0 ) { QString maj = (*it).left( pos ); maj[0] = maj[0].upper(); types << tr("All %1 files").arg(maj); } } if ( filters.count() > 1 ) { typelist.append( filter ); types << tr("All files"); } prev = currentText(); clear(); insertStringList(types); for (int i=0; i<count(); i++) { if ( text(i) == prev ) { setCurrentItem(i); break; } } if ( prev.isNull() ) setCurrentItem(count()-1); setEnabled( TRUE ); } //=========================================================================== FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) : QListViewItem( parent ), fl( f ) { setText( 0, f.name() ); setPixmap( 0, f.pixmap() ); } FileSelectorItem::~FileSelectorItem() { } FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) : QListView( parent, name ) { setAllColumnsShowFocus( TRUE ); addColumn( tr( "Name" ) ); header()->hide(); } FileSelectorView::~FileSelectorView() { } void FileSelectorView::keyPressEvent( QKeyEvent *e ) { QString txt = e->text(); if (e->key() == Key_Space) emit returnPressed( currentItem() ); else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) e->ignore(); else QListView::keyPressEvent(e); } class NewDocItem : public FileSelectorItem { public: NewDocItem( QListView *parent, const DocLnk &f ) : FileSelectorItem( parent, f ) { setText( 0, QObject::tr("New Document") ); QImage img( Resource::loadImage( "new" ) ); QPixmap pm; pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); setPixmap( 0, pm ); } QString key ( int, bool ) const { return QString("\n"); } void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QFont oldFont = p->font(); QFont newFont = p->font(); newFont.setWeight( QFont::Bold ); p->setFont( newFont ); FileSelectorItem::paintCell( p, cg, column, width, alignment ); p->setFont( oldFont ); } int width( const QFontMetrics &fm, const QListView *v, int c ) const { return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font } }; //=========================================================================== class FileSelectorPrivate { public: TypeCombo *typeCombo; CategorySelect *catSelect; QValueList<QRegExp> mimeFilters; int catId; bool showNew; NewDocItem *newDocItem; DocLnkSet files; QHBox *toolbar; }; /*! \class FileSelector fileselector.h \brief The FileSelector widget allows the user to select DocLnk objects. This class presents a file selection dialog to the user. This widget is usually the first widget seen in a \link docwidget.html document-oriented application\endlink. The developer will most often create this widget in combination with a <a href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate editor and/or viewer widget for their application. This widget should be shown first and the user can the select which document they wish to operate on. Please refer to the implementation of texteditor for an example of how to tie these classes together. Use setNewVisible() depending on whether the application can be used to create new files or not. Use setCloseVisible() depending on whether the user may leave the dialog without creating or selecting a document or not. The number of files in the view is available from fileCount(). To force the view to be updated call reread(). If the user presses the 'New Document' button the newSelected() signal is emitted. If the user selects an existing file the fileSelected() signal is emitted. The selected file's \link doclnk.html DocLnk\endlink is available from the selected() function. If the file selector is no longer necessary the closeMe() signal is emitted. \ingroup qtopiaemb \sa FileManager */ /*! Constructs a FileSelector with mime filter \a f. The standard Qt \a parent and \a name parameters are passed to the parent widget. If \a newVisible is TRUE, the widget has a button to allow the user the create "new" documents; this is useful for applications that can create and edit documents but not suitable for applications that only provide viewing. \a closeVisible is deprecated \sa DocLnkSet::DocLnkSet() */ FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) : QVBox( parent, name ), filter( f ) { setMargin( 0 ); setSpacing( 0 ); d = new FileSelectorPrivate(); d->newDocItem = 0; d->showNew = newVisible; d->catId = -2; // All files d->toolbar = new QHBox( this ); d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars d->toolbar->setSpacing( 0 ); d->toolbar->hide(); QWidget *spacer = new QWidget( d->toolbar ); spacer->setBackgroundMode( PaletteButton ); QToolButton *tb = new QToolButton( d->toolbar ); tb->setPixmap( Resource::loadPixmap( "close" ) ); connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); buttonClose = tb; tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); tb->setAutoRaise( TRUE ); QToolTip::add( tb, tr( "Close the File Selector" ) ); QPEMenuToolFocusManager::manager()->addWidget( tb ); view = new FileSelectorView( this, "fileview" ); QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); connect( view, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( fileClicked( QListViewItem * ) ) ); QHBox *hb = new QHBox( this ); d->typeCombo = new TypeCombo( hb ); connect( d->typeCombo, SIGNAL(selected(const QString&)), this, SLOT(typeSelected(const QString&)) ); QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); Categories c; c.load(categoryFileName()); QArray<int> vl( 0 ); d->catSelect = new CategorySelect( hb ); d->catSelect->setRemoveCategoryEdit( TRUE ); d->catSelect->setCategories( vl, "Document View", tr("Document View") ); d->catSelect->setAllCategories( TRUE ); connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); setCloseVisible( closeVisible ); QCopChannel *channel = new QCopChannel( "QPE/Card", this ); connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); reread(); updateWhatsThis(); } /*! Destroys the widget. */ FileSelector::~FileSelector() { delete d; } /*! Returns the number of files in the view. If this is zero, an editor application might bypass the selector and immediately start with a "new" document. */ int FileSelector::fileCount() { return d->files.children().count();; } /*! Calling this function is the programmatic equivalent of the user pressing the "new" button. \sa newSelected(), closeMe() */ void FileSelector::createNew() { DocLnk f; emit newSelected( f ); emit closeMe(); } void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) { if ( !i ) return; if ( button == Qt::LeftButton ) { fileClicked( i ); } } void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) { if ( !i || i == d->newDocItem ) return; if ( button == Qt::RightButton ) { DocLnk l = ((FileSelectorItem *)i)->file(); LnkProperties prop( &l ); prop.showMaximized(); prop.exec(); reread(); } } void FileSelector::fileClicked( QListViewItem *i ) { if ( !i ) return; if ( i == d->newDocItem ) { createNew(); } else { emit fileSelected( ( (FileSelectorItem*)i )->file() ); emit closeMe(); } } void FileSelector::typeSelected( const QString &type ) { d->mimeFilters.clear(); QStringList subFilter = QStringList::split(";", type); for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); updateView(); } void FileSelector::catSelected( int c ) { d->catId = c; updateView(); } void FileSelector::cardMessage( const QCString &msg, const QByteArray &) { if ( msg == "mtabChanged()" ) reread(); } /*! Returns the selected \link doclnk.html DocLnk\endlink. The caller is responsible for deleting the returned value. */ const DocLnk *FileSelector::selected() { FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); if ( item && item != d->newDocItem ) return new DocLnk( item->file() ); return NULL; } /*! \fn void FileSelector::fileSelected( const DocLnk &f ) This signal is emitted when the user selects a document. \a f is the document. */ /*! \fn void FileSelector::newSelected( const DocLnk &f ) This signal is emitted when the user selects a "new" document. \a f is a DocLnk for the document. You will need to set the type of the document after copying it. */ /*! \fn void FileSelector::closeMe() This signal is emitted when the user no longer needs to view the widget. */ /*! If \a b is TRUE a "new document" entry is visible; if \a b is FALSE this entry is not visible and the user is unable to create new documents from the dialog. */ void FileSelector::setNewVisible( bool b ) { if ( d->showNew != b ) { d->showNew = b; updateView(); updateWhatsThis(); } } /*! If \a b is TRUE a "close" or "no document" button is visible; if \a b is FALSE this button is not visible and the user is unable to leave the dialog without creating or selecting a document. This function is deprecated. */ void FileSelector::setCloseVisible( bool b ) { if ( b ) d->toolbar->show(); else d->toolbar->hide(); } /*! */ void FileSelector::setTypeComboVisible( bool b ) { if ( b ) d->typeCombo->show(); else d->typeCombo->hide(); } /*! */ void FileSelector::setCategorySelectVisible( bool b ) { if ( b ) d->catSelect->show(); else d->catSelect->hide(); } /*! Rereads the list of documents. */ void FileSelector::reread() { d->files.clear(); Global::findDocuments(&d->files, filter); d->typeCombo->reread( d->files, filter ); updateView(); } void FileSelector::updateView() { FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); if ( item == d->newDocItem ) item = 0; QString oldFile; if ( item ) oldFile = item->file().file(); view->clear(); QListIterator<DocLnk> dit( d->files.children() ); for ( ; dit.current(); ++dit ) { bool mimeMatch = FALSE; if ( d->mimeFilters.count() ) { QValueList<QRegExp>::Iterator it; for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { if ( (*it).match((*dit)->type()) >= 0 ) { mimeMatch = TRUE; break; } } } else { mimeMatch = TRUE; } if ( mimeMatch && (d->catId == -2 || (*dit)->categories().contains(d->catId) || (d->catId == -1 && (*dit)->categories().isEmpty())) ) { item = new FileSelectorItem( view, **dit ); if ( item->file().file() == oldFile ) view->setCurrentItem( item ); } } if ( d->showNew ) d->newDocItem = new NewDocItem( view, DocLnk() ); else d->newDocItem = 0; if ( !view->selectedItem() || view->childCount() == 1 ) { view->setCurrentItem( view->firstChild() ); view->setSelected( view->firstChild(), TRUE ); } } void FileSelector::updateWhatsThis() { QWhatsThis::remove( this ); QString text = tr("Click to select a document from the list"); if ( d->showNew ) text += tr(", or select <b>New Document</b> to create a new document."); text += tr("<br><br>Click and hold for document properties."); QWhatsThis::add( this, text ); } #include "fileselector.moc" diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp index 2b5e0d2..147134c 100644 --- a/library/fontdatabase.cpp +++ b/library/fontdatabase.cpp @@ -1,232 +1,230 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qpe/qpeapplication.h> #include "fontfactoryinterface.h" #include "fontdatabase.h" #include <qpe/qlibrary.h> -#ifdef QWS #include <qfontmanager_qws.h> -#endif #include <qdir.h> #include <qdict.h> #include <stdio.h> #include <stdlib.h> static QString fontDir() { QString qtdir = getenv("QTDIR"); if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; return qtdir+"/lib/fonts/"; } #ifdef QT_NO_FONTDATABASE static QString fontFamily( const QString& key ) { int u0 = key.find('_'); int u1 = key.find('_',u0+1); int u2 = key.find('_',u1+1); QString family = key.left(u0); //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); //int weight = key.mid(u1+1,u2-u1-1).toInt(); //bool italic = key.mid(u2-1,1) == "i"; // #### ignores _t and _I fields return family; } #endif QValueList<FontFactory> *FontDatabase::factoryList = 0; /*! \class FontDatabase fontdatabase.h \brief The FontDatabase class provides information about available fonts. Most often you will simply want to query the database for the available font families(). Use FontDatabase rather than QFontDatabase when you may need access to fonts that are not normally available. For example, if the freetype library and the Qtopia freetype plugin are installed, TrueType fonts will be available to your application. Font renderer plugins have greater resource requirements than system fonts so they should be used only when necessary. You can force the loading of font renderer plugins with loadRenderers(). \ingroup qtopiaemb */ /*! Constructs a FontDatabase object. */ FontDatabase::FontDatabase() #ifndef QT_NO_FONTDATABASE : QFontDatabase() #endif { if ( !factoryList ) loadRenderers(); } /*! Returns a list of names of all the available font families. */ QStringList FontDatabase::families() const { #ifndef QT_NO_FONTDATABASE return QFontDatabase::families(); #else QStringList list; QDict<void> familyDict; QDiskFont *qdf; for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; qdf=qt_fontmanager->diskfonts.next()) { QString familyname = qdf->name; if ( !familyDict.find( familyname ) ) { familyDict.insert( familyname, (void *)1 ); list.append( familyname ); } } QDir dir(fontDir(),"*.qpf"); for (int i=0; i<(int)dir.count(); i++) { QString familyname = fontFamily(dir[i]); if ( !familyDict.find( familyname ) ) { familyDict.insert( familyname, (void *)1 ); list.append( familyname ); } } return list; #endif } #ifdef QT_NO_FONTDATABASE /*! Returns a list of standard fontsizes. */ QValueList<int> FontDatabase::standardSizes() { static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 }; static bool first = TRUE; static QValueList<int> sList; if ( first ) { first = FALSE; int i = 0; while( s[i] ) sList.append( s[i++] ); } return sList; } #endif /*! Load any font renderer plugins that are available and make the fonts that the plugins can read available. */ void FontDatabase::loadRenderers() { #ifndef QT_NO_COMPONENT if ( !factoryList ) factoryList = new QValueList<FontFactory>; QValueList<FontFactory>::Iterator mit; for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { qt_fontmanager->factories.setAutoDelete( false ); qt_fontmanager->factories.removeRef( (*mit).factory ); qt_fontmanager->factories.setAutoDelete( true ); (*mit).interface->release(); (*mit).library->unload(); delete (*mit).library; } factoryList->clear(); QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; QDir dir( path, "lib*.so" ); QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { FontFactoryInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { FontFactory factory; factory.library = lib; factory.interface = iface; factory.factory = factory.interface->fontFactory(); factoryList->append( factory ); qt_fontmanager->factories.append( factory.factory ); readFonts( factory.factory ); } else { delete lib; } } #endif } /*! \internal */ void FontDatabase::readFonts( QFontFactory *factory ) { // Load in font definition file QString fn = fontDir() + "fontdir"; FILE* fontdef=fopen(fn.local8Bit(),"r"); if(!fontdef) { QCString temp=fn.local8Bit(); qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", temp.data()); return; } char buf[200]=""; char name[200]=""; char render[200]=""; char file[200]=""; char flags[200]=""; char isitalic[10]=""; fgets(buf,200,fontdef); while(!feof(fontdef)) { if ( buf[0] != '#' ) { int weight=50; int size=0; flags[0]=0; sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); QString filename; if ( file[0] != '/' ) filename = fontDir(); filename += file; if ( QFile::exists(filename) ) { if( factory->name() == render ) { QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', weight,size,flags,filename); qt_fontmanager->diskfonts.append(qdf); #if QT_VERSION >= 232 QFontDatabase::qwsAddDiskFont( qdf ); #endif } } } fgets(buf,200,fontdef); } fclose(fontdef); } diff --git a/library/fontmanager.cpp b/library/fontmanager.cpp index 28a5212..c854133 100644 --- a/library/fontmanager.cpp +++ b/library/fontmanager.cpp @@ -1,103 +1,101 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#ifdef QWS #include "fontmanager.h" #include <qfile.h> #include <stdlib.h> #include <qgfx_qws.h> /* QFontInfo doesn't work in QWS at the moment, otherwise we would just have used that to check the real values For now, there are only two Unicode fonts in the known universe... */ bool FontManager::hasUnicodeFont() { QString fontDir = getenv("QTDIR") + QString("/lib/fonts/"); QString suffix; if ( qt_screen->isTransformed() ) { suffix += "_t"; QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2)); QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2)); suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) ); } suffix += ".qpf"; return QFile::exists( fontDir+"cyberbit_120_50"+suffix ) || QFile::exists( fontDir+"unifont_160_50"+suffix ) || QFile::exists( fontDir+"arial_140_50" + suffix ); } QFont FontManager::unicodeFont( Spacing sp ) { QString key; QString fontName; QString fontDir = getenv("QTDIR") + QString("/lib/fonts/"); int size; if ( sp == Proportional ) { fontName = "Arial"; size=14; key = "arial_140_50"; } else { fontName = "Unifont"; size=16; key = "unifont_160_50"; } QString suffix; if ( qt_screen->isTransformed() ) { suffix += "_t"; QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2)); QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2)); suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) ); } suffix += ".qpf"; // if we cannot find it, try the other one if ( !QFile::exists(fontDir+key+suffix) ) { key = (sp == Fixed ) ? "arial_140_50" : "unifont_160_50"; if ( QFile::exists(fontDir+key+suffix) ) { fontName = (sp == Fixed) ? "Arial" : "Unifont"; size = (sp == Fixed) ? 14 : 16; } else { key = "cyberbit_120_50"; if ( QFile::exists(fontDir+key+suffix) ) { fontName = "Cyberbit"; size = 12; } else { fontName = "Helvetica"; size = 14; } } } return QFont(fontName,size); } -#endif diff --git a/library/global.cpp b/library/global.cpp index 9b908bf..d02e711 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -1,812 +1,806 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_LANGLIST #include <qpe/qpedebug.h> #include <qpe/global.h> #include <qpe/qdawg.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/storage.h> #include <qpe/applnk.h> -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) -#include "qpe/qcopenvelope_qws.h" -#endif +#include <qpe/qcopenvelope_qws.h> #include <qfile.h> #include <qlabel.h> #include <qtimer.h> #include <qmap.h> #include <qdict.h> #include <qdir.h> #include <qmessagebox.h> #include <qregexp.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> -#ifdef QWS #include <qwindowsystem_qws.h> // for qwsServer -#endif #include <qdatetime.h> #include <qfile.h> namespace { // checks if the storage should be searched bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke QFile file(path ); if(!file.open(IO_ReadOnly ) ) return true; QByteArray array = file.readAll(); QStringList list = QStringList::split('\n', QString( array ) ); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ if( (*it).startsWith("autocheck = 0" ) ){ return false; }else if( (*it).startsWith("autocheck = 1" ) ){ return true; } } return true; } } //#include "quickexec_p.h" class Emitter : public QObject { Q_OBJECT public: Emitter( QWidget* receiver, const QString& document ) { connect(this, SIGNAL(setDocument(const QString&)), receiver, SLOT(setDocument(const QString&))); emit setDocument(document); disconnect(this, SIGNAL(setDocument(const QString&)), receiver, SLOT(setDocument(const QString&))); } signals: void setDocument(const QString&); }; class StartingAppList : public QObject { Q_OBJECT public: static void add( const QString& name ); static bool isStarting( const QString name ); private slots: void handleNewChannel( const QString &); private: StartingAppList( QObject *parent=0, const char* name=0 ) ; QDict<QTime> dict; static StartingAppList *appl; }; StartingAppList* StartingAppList::appl = 0; StartingAppList::StartingAppList( QObject *parent, const char* name ) :QObject( parent, name ) { -#ifdef QWS #if QT_VERSION >= 232 && !defined(QT_NO_COP) connect( qwsServer, SIGNAL( newChannel(const QString&)), this, SLOT( handleNewChannel(const QString&)) ); dict.setAutoDelete( TRUE ); #endif -#endif } void StartingAppList::add( const QString& name ) { #if QT_VERSION >= 232 && !defined(QT_NO_COP) if ( !appl ) appl = new StartingAppList; QTime *t = new QTime; t->start(); appl->dict.insert( "QPE/Application/" + name, t ); #endif } bool StartingAppList::isStarting( const QString name ) { #if QT_VERSION >= 232 && !defined(QT_NO_COP) if ( appl ) { QTime *t = appl->dict.find( "QPE/Application/" + name ); if ( !t ) return FALSE; if ( t->elapsed() > 10000 ) { // timeout in case of crash or something appl->dict.remove( "QPE/Application/" + name ); return FALSE; } return TRUE; } #endif return FALSE; } void StartingAppList::handleNewChannel( const QString & name ) { #if QT_VERSION >= 232 && !defined(QT_NO_COP) dict.remove( name ); #endif } static bool docDirCreated = FALSE; static QDawg* fixed_dawg = 0; static QDict<QDawg> *named_dawg = 0; static QString qpeDir() { QString dir = getenv("OPIEDIR"); if ( dir.isEmpty() ) dir = ".."; return dir; } static QString dictDir() { return qpeDir() + "/etc/dict"; } /*! \class Global global.h \brief The Global class provides application-wide global functions. The Global functions are grouped as follows: \tableofcontents \section1 User Interface The statusMessage() function provides short-duration messages to the user. The showInputMethod() function shows the current input method, and hideInputMethod() hides the input method. \section1 Document related The findDocuments() function creates a set of \link doclnk.html DocLnk\endlink objects in a particular folder. \section1 Filesystem related Global provides an applicationFileName() function that returns the full path of an application-specific file. The execute() function runs an application. \section1 Word list related A list of words relevant to the current locale is maintained by the system. The list is held in a \link qdawg.html DAWG\endlink (implemented by the QDawg class). This list is used, for example, by the pickboard input method. The global QDawg is returned by fixedDawg(); this cannot be updated. An updatable copy of the global QDawg is returned by addedDawg(). Applications may have their own word lists stored in \l{QDawg}s which are returned by dawg(). Use addWords() to add words to the updateable copy of the global QDawg or to named application \l{QDawg}s. \section1 Quoting The shellQuote() function quotes a string suitable for passing to a shell. The stringQuote() function backslash escapes '\' and '"' characters. \section1 Hardware The writeHWClock() function sets the hardware clock to the system clock's date and time. \ingroup qtopiaemb */ /*! \internal */ Global::Global() { } /*! Returns the unchangeable QDawg that contains general words for the current locale. \sa addedDawg() */ const QDawg& Global::fixedDawg() { if ( !fixed_dawg ) { if ( !docDirCreated ) createDocDir(); fixed_dawg = new QDawg; QString dawgfilename = dictDir() + "/dawg"; QString words_lang; QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { QString lang = *it; words_lang = dictDir() + "/words." + lang; QString dawgfilename_lang = dawgfilename + "." + lang; if ( QFile::exists(dawgfilename_lang) || QFile::exists(words_lang) ) { dawgfilename = dawgfilename_lang; break; } } QFile dawgfile(dawgfilename); if ( !dawgfile.exists() ) { QString fn = dictDir() + "/words"; if ( QFile::exists(words_lang) ) fn = words_lang; QFile in(fn); if ( in.open(IO_ReadOnly) ) { fixed_dawg->createFromWords(&in); dawgfile.open(IO_WriteOnly); fixed_dawg->write(&dawgfile); dawgfile.close(); } } else { fixed_dawg->readFile(dawgfilename); } } return *fixed_dawg; } /*! Returns the changeable QDawg that contains general words for the current locale. \sa fixedDawg() */ const QDawg& Global::addedDawg() { return dawg("local"); } /*! Returns the QDawg with the given \a name. This is an application-specific word list. \a name should not contain "/". */ const QDawg& Global::dawg(const QString& name) { createDocDir(); if ( !named_dawg ) named_dawg = new QDict<QDawg>; QDawg* r = named_dawg->find(name); if ( !r ) { r = new QDawg; named_dawg->insert(name,r); QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; QFile dawgfile(dawgfilename); if ( dawgfile.open(IO_ReadOnly) ) r->readFile(dawgfilename); } return *r; } /*! \overload Adds \a wordlist to the addedDawg(). Note that the addition of words persists between program executions (they are saved in the dictionary files), so you should confirm the words with the user before adding them. */ void Global::addWords(const QStringList& wordlist) { addWords("local",wordlist); } /*! \overload Adds \a wordlist to the addedDawg(). Note that the addition of words persists between program executions (they are saved in the dictionary files), so you should confirm the words with the user before adding them. */ void Global::addWords(const QString& dictname, const QStringList& wordlist) { QDawg& d = (QDawg&)dawg(dictname); QStringList all = d.allWords() + wordlist; d.createFromWords(all); QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; QFile dawgfile(dawgfilename); if ( dawgfile.open(IO_WriteOnly) ) { d.write(&dawgfile); dawgfile.close(); } // #### Re-read the dawg here if we use mmap(). // #### Signal other processes to re-read. } /*! Returns the full path for the application called \a appname, with the given \a filename. Returns QString::null if there was a problem creating the directory tree for \a appname. If \a filename contains "/", it is the caller's responsibility to ensure that those directories exist. */ QString Global::applicationFileName(const QString& appname, const QString& filename) { QDir d; QString r = getenv("HOME"); r += "/Applications/"; if ( !QFile::exists( r ) ) if ( d.mkdir(r) == false ) return QString::null; r += appname; if ( !QFile::exists( r ) ) if ( d.mkdir(r) == false ) return QString::null; r += "/"; r += filename; return r; } /*! \internal */ void Global::createDocDir() { if ( !docDirCreated ) { docDirCreated = TRUE; mkdir( QPEApplication::documentDir().latin1(), 0755 ); } } /*! Displays a status \a message to the user. This usually appears in the taskbar for a short amount of time, then disappears. */ void Global::statusMessage(const QString& message) { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if!defined(QT_NO_COP) QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); e << message; #endif } /*! \internal */ void Global::applyStyle() { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QCopChannel::send( "QPE/System", "applyStyle()" ); #else ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version #endif } /*! \internal */ QWidget *Global::shutdown( bool ) { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QCopChannel::send( "QPE/System", "shutdown()" ); #endif return 0; } /*! \internal */ QWidget *Global::restart( bool ) { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QCopChannel::send( "QPE/System", "restart()" ); #endif return 0; } /*! Explicitly show the current input method. Input methods are indicated in the taskbar by a small icon. If the input method is activated (shown) then it takes up some proportion of the bottom of the screen, to allow the user to interact (input characters) with it. \sa hideInputMethod() */ void Global::showInputMethod() { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); #endif } /*! Explicitly hide the current input method. The current input method is still indicated in the taskbar, but no longer takes up screen space, and can no longer be interacted with. \sa showInputMethod() */ void Global::hideInputMethod() { -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); #endif } /*! \internal */ bool Global::isBuiltinCommand( const QString &name ) { if(!builtin) return FALSE; // yes, it can happen for (int i = 0; builtin[i].file; i++) { if ( builtin[i].file == name ) { return TRUE; } } return FALSE; } Global::Command* Global::builtin=0; QGuardedPtr<QWidget> *Global::running=0; /*! \class Global::Command \brief The Global::Command class is internal. \internal */ /*! \internal */ void Global::setBuiltinCommands( Command* list ) { if ( running ) delete [] running; builtin = list; int count = 0; if (!builtin) return; while ( builtin[count].file ) count++; running = new QGuardedPtr<QWidget> [ count ]; } /*! \internal */ void Global::setDocument( QWidget* receiver, const QString& document ) { Emitter emitter(receiver,document); } /*! \internal */ bool Global::terminateBuiltin( const QString& n ) { if (!builtin) return FALSE; for (int i = 0; builtin[i].file; i++) { if ( builtin[i].file == n ) { delete running[i]; return TRUE; } } return FALSE; } /*! \internal */ void Global::terminate( const AppLnk* app ) { //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this #ifndef QT_NO_COP QCString channel = "QPE/Application/" + app->exec().utf8(); if ( QCopChannel::isRegistered(channel) ) { QCopEnvelope e(channel, "quit()"); } #endif } /*! Low-level function to run command \a c. \warning Do not use this function. Use execute instead. \sa execute() */ void Global::invoke(const QString &c) { // Convert the command line in to a list of arguments QStringList list = QStringList::split(QRegExp(" *"),c); -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QString ap=list[0]; // see if the application is already running // XXX should lock file /tmp/qcop-msg-ap if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { // If the channel is already register, the app is already running, so show it. { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } QCopEnvelope e("QPE/System", "notBusy(QString)" ); e << ap; return; } // XXX should unlock file /tmp/qcop-msg-ap //see if it is being started if ( StartingAppList::isStarting( ap ) ) { QCopEnvelope e("QPE/System", "notBusy(QString)" ); e << ap; return; } #endif #ifdef QT_NO_QWS_MULTIPROCESS QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); #else QStrList slist; unsigned int j; for ( j = 0; j < list.count(); j++ ) slist.append( list[j].utf8() ); const char **args = new (const char *)[slist.count() + 1]; for ( j = 0; j < slist.count(); j++ ) args[j] = slist.at(j); args[j] = NULL; -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) // an attempt to show a wait... // more logic should be used, but this will be fine for the moment... QCopEnvelope ( "QPE/System", "busy()" ); #endif #ifdef HAVE_QUICKEXEC QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; qDebug("libfile = %s", libexe.latin1() ); if ( QFile::exists( libexe ) ) { qDebug("calling quickexec %s", libexe.latin1() ); quickexecv( libexe.utf8().data(), (const char **)args ); } else #endif { if ( !::vfork() ) { for ( int fd = 3; fd < 100; fd++ ) ::close( fd ); ::setpgid( ::getpid(), ::getppid() ); // Try bindir first, so that foo/bar works too ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); ::execvp( args[0], (char * const *)args ); _exit( -1 ); } } StartingAppList::add( list[0] ); #endif //QT_NO_QWS_MULTIPROCESS } /*! Executes the application identfied by \a c, passing \a document if it isn't null. Note that a better approach might be to send a QCop message to the application's QPE/Application/\e{appname} channel. */ void Global::execute( const QString &c, const QString& document ) { if ( qApp->type() != QApplication::GuiServer ) { // ask the server to do the work -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) if ( document.isNull() ) { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << c; } else { QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); e << c << document; } #endif return; } // Attempt to execute the app using a builtin class for the app first // else try and find it in the bin directory if (builtin) { for (int i = 0; builtin[i].file; i++) { if ( builtin[i].file == c ) { if ( running[i] ) { if ( !document.isNull() && builtin[i].documentary ) setDocument(running[i], document); running[i]->raise(); running[i]->show(); running[i]->setActiveWindow(); } else { running[i] = builtin[i].func( builtin[i].maximized ); } #ifndef QT_NO_COP QCopEnvelope e("QPE/System", "notBusy(QString)" ); e << c; // that was quick ;-) #endif return; } } } //Global::invoke(c, document); // Convert the command line in to a list of arguments QStringList list = QStringList::split(QRegExp(" *"),c); -#if defined(Q_WS_QWS) && !defined(QT_NO_COP) +#if !defined(QT_NO_COP) QString ap=list[0]; qDebug("executing %s", ap.latin1() ); /* if need be, sending a qcop message will result in an invoke, see preceeding function */ invoke( ap ); //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } if ( !document.isEmpty() ) { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); env << document; } #endif } /*! Returns the string \a s with the characters '\', '"', and '$' quoted by a preceeding '\'. \sa stringQuote() */ QString Global::shellQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': case '$': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Returns the string \a s with the characters '\' and '"' quoted by a preceeding '\'. \sa shellQuote() */ QString Global::stringQuote(const QString& s) { QString r="\""; for (int i=0; i<(int)s.length(); i++) { char c = s[i].latin1(); switch (c) { case '\\': case '"': r+="\\"; } r += s[i]; } r += "\""; return r; } /*! Finds all documents on the system's document directories which match the filter \a mimefilter, and appends the resulting DocLnk objects to \a folder. */ void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) { QString homedocs = QString(getenv("HOME")) + "/Documents"; DocLnkSet d(homedocs,mimefilter); folder->appendFrom(d); /** let's do intellegint way of searching these files * a) the user don't want to check mediums global * b) the user wants to check but use the global options for it * c) the user wants to check it but not this medium * d) the user wants to check and this medium as well * * In all cases we need to apply a different mimefilter to * the medium. * a) mimefilter.isEmpty() we need to apply the responding filter * either the global or the one on the medium * * b) mimefilter is set to an application we need to find out if the * mimetypes are included in the mime mask of the medium */ StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { // let's find out if we should search on it // this is a candidate look at the cf and see if we should search on it QString path = (*it)->path(); if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) continue; DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { QString path = (*it)->path() + "/Documents"; DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } } } QStringList Global::languageList() { QString lang = getenv("LANG"); QStringList langs; langs.append(lang); int i = lang.find("."); if ( i > 0 ) lang = lang.left( i ); i = lang.find( "_" ); if ( i > 0 ) langs.append(lang.left(i)); return langs; } QStringList Global::helpPath() { QStringList path; QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { QString lang = *it; if ( !lang.isEmpty() ) path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; } path += QPEApplication::qpeDir() + "/pics"; path += QPEApplication::qpeDir() + "/help/html"; path += QPEApplication::qpeDir() + "/docs"; return path; } #include "global.moc" diff --git a/library/ir.cpp b/library/ir.cpp index a7cf7b1..b5b726d 100644 --- a/library/ir.cpp +++ b/library/ir.cpp @@ -1,120 +1,118 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "ir.h" #include <qstring.h> -#ifdef QWS #include "qcopenvelope_qws.h" #include <qcopchannel_qws.h> -#endif #include "applnk.h" /*! \class Ir ir.h \brief The Ir class implements basic support for sending objects over an infrared communication link. Both \link doclnk.html DocLnk\endlink objects and files can be sent to another device via the infrared link using the send() function. When the send has completed the done() signal is emitted. The supported() function returns whether the device supports infrared communication or not. \ingroup qtopiaemb */ /*! Constructs an Ir object. The \a parent and \a name classes are the standard QObject parameters. */ Ir::Ir( QObject *parent, const char *name ) : QObject( parent, name ) { #ifndef QT_NO_COP ch = new QCopChannel( "QPE/Obex" ); connect( ch, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(obexMessage( const QCString &, const QByteArray &)) ); #endif } /*! Returns TRUE if the system supports infrared communication; otherwise returns FALSE. */ bool Ir::supported() { #ifndef QT_NO_COP return QCopChannel::isRegistered( "QPE/Obex" ); #endif } /*! Sends the object in file \a fn over the infrared link. The \a description is used in the text shown to the user while sending is in progress. The optional \a mimetype parameter specifies the mimetype of the object. If this parameter is not set, it is determined by the the filename's suffix. \sa done() */ void Ir::send( const QString &fn, const QString &description, const QString &mimetype) { if ( !filename.isEmpty() ) return; filename = fn; #ifndef QT_NO_COP QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)"); e << description << filename << mimetype; #endif } /*! \overload Uses the DocLnk::file() and DocLnk::type() of \a doc. \sa done() */ void Ir::send( const DocLnk &doc, const QString &description ) { send( doc.file(), description, doc.type() ); } /*! \fn Ir::done( Ir *ir ); This signal is emitted by \a ir, when the send comand has been processed. */ /*!\internal */ void Ir::obexMessage( const QCString &msg, const QByteArray &data) { if ( msg == "done(QString)" ) { QString fn; QDataStream stream( data, IO_ReadOnly ); stream >> fn; if ( fn == filename ) emit done( this ); } } diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp index 0b50bae..50cf5af 100644 --- a/library/lnkproperties.cpp +++ b/library/lnkproperties.cpp @@ -1,342 +1,340 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT // have this class. #define QTOPIA_INTERNAL_FSLP #include "lnkproperties.h" #include "lnkproperties.h" #include "lnkpropertiesbase_p.h" #include "ir.h" #include <qpe/qpeapplication.h> #include <qpe/applnk.h> #include <qpe/global.h> #include <qpe/categorywidget.h> -#ifdef QWS #include <qpe/qcopenvelope_qws.h> -#endif #include <qpe/filemanager.h> #include <qpe/config.h> #include <qpe/storage.h> #include <qpe/qpemessagebox.h> #include <qpe/mimetype.h> #include <qlineedit.h> #include <qtoolbutton.h> #include <qpushbutton.h> #include <qgroupbox.h> #include <qcheckbox.h> #include <qlabel.h> #include <qlayout.h> #include <qfile.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qsize.h> #include <qcombobox.h> #include <qregexp.h> #include <qbuttongroup.h> #include <stdlib.h> LnkProperties::LnkProperties( AppLnk* l, QWidget* parent ) : QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 ) { setCaption( tr("Properties") ); QVBoxLayout *vbox = new QVBoxLayout( this ); d = new LnkPropertiesBase( this ); vbox->add( d ); d->docname->setText(l->name()); QString inf; if ( l->type().isEmpty() ) { d->type->hide(); d->typeLabel->hide(); } else { d->type->setText( l->type() ); } if ( l->comment().isEmpty() ) { d->comment->hide(); d->commentLabel->hide(); } else { d->comment->setText( l->comment() ); } connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk())); if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed) connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk())); connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk())); d->docname->setReadOnly( FALSE ); d->preload->hide(); d->rotate->hide(); d->rotateButtons->hide(); d->labelspacer->hide(); // ### THIS MUST GO, FIX WIERD BUG in QLAYOUT d->categoryEdit->kludge(); d->categoryEdit->setCategories( lnk->categories(), "Document View", tr("Document View") ); setupLocations(); } else { d->unlink->hide(); d->duplicate->hide(); d->beam->hide(); d->hline->hide(); d->locationLabel->hide(); d->locationCombo->hide(); // Can't edit categories, since the app .desktop files are global, // possibly read-only. d->categoryEdit->hide(); d->docname->setReadOnly( TRUE ); if ( l->property("CanFastload") == "0" ) d->preload->hide(); if ( !l->property("Rotation"). isEmpty ()) { d->rotate->setChecked ( true ); d->rotateButtons->setButton((l->rotation().toInt()%360)/90); } else { d->rotateButtons->setEnabled(false); } Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps",','); d->preload->setChecked( apps.contains(l->exec()) ); if ( Global::isBuiltinCommand(lnk->exec()) ) d->preload->hide(); // builtins are always fast currentLocation = 0; // apps not movable (yet) } } LnkProperties::~LnkProperties() { } void LnkProperties::unlinkLnk() { if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) { lnk->removeFiles(); if ( QFile::exists(lnk->file()) ) { QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") ); } else { reject(); } } } void LnkProperties::setupLocations() { QFileInfo fi( lnk->file() ); fileSize = fi.size(); StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); QString s; QString homeDir = getenv("HOME"); QString hardDiskHome; QString hardDiskPath; int index = 0; currentLocation = -1; for ( ; it.current(); ++it ) { // we add 10k to the file size so we are sure we can also save the desktop file if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) { if ( (*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock1" || (*it)->disk() == "/dev/mtdblock/1" || (*it)->disk().left(13) == "/dev/mtdblock" || (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { d->locationCombo->insertItem( (*it)->name(), index ); locations.append( ( ((*it)->isRemovable() || (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) ? (*it)->path() : homeDir) ); if ( lnk->file().contains( (*it)->path() ) ) { d->locationCombo->setCurrentItem( index ); currentLocation = index; } index++; } else if ( (*it)->name().contains( tr("Hard Disk") ) && homeDir.contains( (*it)->path() ) && (*it)->path().length() > hardDiskHome.length() ) { hardDiskHome = (*it)->name(); hardDiskPath = (*it)->path(); } } } if ( !hardDiskHome.isEmpty() ) { d->locationCombo->insertItem( hardDiskHome ); locations.append( hardDiskPath ); if ( currentLocation == -1 ) { // assume it's the hard disk d->locationCombo->setCurrentItem( index ); currentLocation = index; } } } void LnkProperties::duplicateLnk() { // The duplicate takes the new properties. DocLnk newdoc( *((DocLnk *)lnk) ); if ( d->docname->text() == lnk->name() ) newdoc.setName(tr("Copy of ")+d->docname->text()); else newdoc.setName(d->docname->text()); if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") ); return; } reject(); } bool LnkProperties::moveLnk() { DocLnk newdoc( *((DocLnk *)lnk) ); newdoc.setName(d->docname->text()); if ( !copyFile( newdoc ) ) { QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") ); return FALSE; } // remove old lnk lnk->removeFiles(); return TRUE; } void LnkProperties::beamLnk() { Ir ir; DocLnk doc( *((DocLnk *)lnk) ); doc.setName(d->docname->text()); reject(); ir.send( doc, doc.comment() ); } bool LnkProperties::copyFile( DocLnk &newdoc ) { const char *linkExtn = ".desktop"; QString fileExtn; int extnPos = lnk->file().findRev( '.' ); if ( extnPos > 0 ) fileExtn = lnk->file().mid( extnPos ); QString safename = newdoc.name(); safename.replace(QRegExp("/"),"_"); QString fn = locations[ d->locationCombo->currentItem() ] + "/Documents/" + newdoc.type() + "/" + safename; if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) { int n=1; QString nn = fn + "_" + QString::number(n); while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) { n++; nn = fn + "_" + QString::number(n); } fn = nn; } newdoc.setFile( fn + fileExtn ); newdoc.setLinkFile( fn + linkExtn ); // Copy file FileManager fm; if ( !fm.copyFile( *lnk, newdoc ) ) return FALSE; return TRUE; } void LnkProperties::done(int ok) { if ( ok ) { bool changed=FALSE; bool reloadMime=FALSE; if ( lnk->name() != d->docname->text() ) { lnk->setName(d->docname->text()); changed=TRUE; } if ( d->categoryEdit->isVisible() ) { QArray<int> tmp = d->categoryEdit->newCategories(); if ( lnk->categories() != tmp ) { lnk->setCategories( tmp ); changed = TRUE; } } if ( !d->rotate->isHidden()) { QString newrot; if ( d->rotate->isChecked() ) { int rot=0; for(; rot<4; rot++) { if (d->rotateButtons->find(rot)->isOn()) break; } newrot = QString::number((rot*90)%360); } if ( newrot != lnk->rotation() ) { lnk-> setRotation(newrot); changed = TRUE; reloadMime = TRUE; } } if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) { moveLnk(); } else if ( changed ) { lnk->writeLink(); } if ( !d->preload->isHidden() ) { Config cfg("Launcher"); cfg.setGroup("Preload"); QStringList apps = cfg.readListEntry("Apps",','); QString exe = lnk->exec(); if ( apps.contains(exe) != d->preload->isChecked() ) { if ( d->preload->isChecked() ) { apps.append(exe); #ifndef QT_NO_COP QCopEnvelope e("QPE/Application/"+exe.local8Bit(), "enablePreload()"); #endif } else { apps.remove(exe); #ifndef QT_NO_COP QCopEnvelope e("QPE/Application/"+exe.local8Bit(), "quitIfInvisible()"); #endif } cfg.writeEntry("Apps",apps,','); } } if ( reloadMime ) MimeType::updateApplications ( ); } QDialog::done( ok ); } diff --git a/library/network.cpp b/library/network.cpp index 185b147..3568809 100644 --- a/library/network.cpp +++ b/library/network.cpp @@ -1,446 +1,444 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_LANGLIST #include "qpe/network.h" #include "qpe/networkinterface.h" #include "qpe/global.h" #include "qpe/config.h" #include "qpe/resource.h" #include "qpe/qpeapplication.h" -#ifdef QWS #include <qpe/qcopenvelope_qws.h> -#endif #include <qpe/qlibrary.h> #include <qlistbox.h> #include <qdir.h> #include <qlayout.h> #include <qdict.h> #include <qtranslator.h> #include <stdlib.h> #ifndef QT_NO_COP class NetworkEmitter : public QCopChannel { Q_OBJECT public: NetworkEmitter() : QCopChannel("QPE/Network",qApp) { } void receive(const QCString &msg, const QByteArray&) { if ( msg == "choicesChanged()" ) emit changed(); } signals: void changed(); }; /*! \internal Requests that the service \a choice be started. The \a password is the password to use if required. */ void Network::start(const QString& choice, const QString& password) { QCopEnvelope e("QPE/Network", "start(QString,QString)"); e << choice << password; } /*! \class Network network.h \brief The Network class provides network access functionality. \internal */ // copy the proxy settings of the active config over to the Proxies.conf file /*! \internal */ void Network::writeProxySettings( Config &cfg ) { Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); proxy.setGroup("Properties"); cfg.setGroup("Proxy"); proxy.writeEntry("type", cfg.readEntry("type") ); proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); proxy.writeEntry("httphost", cfg.readEntry("httphost") ); proxy.writeEntry("httpport", cfg.readEntry("httpport") ); proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); cfg.setGroup("Properties"); } /*! \internal Stops the current network service. */ void Network::stop() { QCopEnvelope e("QPE/Network", "stop()"); } static NetworkEmitter *emitter = 0; /*! \internal */ void Network::connectChoiceChange(QObject* receiver, const char* slot) { if ( !emitter ) emitter = new NetworkEmitter; QObject::connect(emitter,SIGNAL(changed()),receiver,slot); } #endif // QT_NO_COP /*! \internal */ QString Network::settingsDir() { return Global::applicationFileName("Network", "modules"); } #ifndef QT_NO_COP /*! \internal */ QStringList Network::choices(QListBox* lb, const QString& dir) { QStringList list; if ( lb ) lb->clear(); QString adir = dir.isEmpty() ? settingsDir() : dir; QDir settingsdir(adir); settingsdir.mkdir(adir); QStringList files = settingsdir.entryList("*.conf"); for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { QString filename = settingsdir.filePath(*it); Config cfg(filename, Config::File); cfg.setGroup("Info"); if ( lb ) lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), cfg.readEntry("Name")); list.append(filename); } return list; } class NetworkServer : public QCopChannel { Q_OBJECT public: NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0) { up = FALSE; examineNetworks( TRUE ); QCopChannel* card = new QCopChannel("QPE/Card",parent); connect(card,SIGNAL(received(const QCString &, const QByteArray&)), this,SLOT(cardMessage(const QCString &, const QByteArray&))); } ~NetworkServer() { stop(); } bool networkOnline() const { return up; } private: void receive(const QCString &msg, const QByteArray& data) { if ( msg == "start(QString,QString)" ) { QDataStream stream(data,IO_ReadOnly); QString file,password; stream >> file >> password; if ( file.isEmpty() ) { QStringList l = Network::choices(); for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { Config cfg(*i,Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); cfg.setGroup("Properties"); if ( plugin && plugin->isAvailable(cfg) ) { file = *i; break; } } if ( file.isEmpty() ) { QCopEnvelope("QPE/Network", "failed()"); return; } } start(file,password); } else if ( msg == "stop()" ) { stop(); } else if ( msg == "choicesChanged()" ) { examineNetworks(); } } private slots: void cardMessage(const QCString &msg, const QByteArray&) { if ( msg == "stabChanged()" ) examineNetworks(); } private: void examineNetworks( bool firstStart = FALSE ) { QStringList l = Network::choices(); bool wasup = up; up=FALSE; QStringList pavailable = available; available.clear(); for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { Config cfg(*it,Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); cfg.setGroup("Properties"); if ( plugin ) { if ( plugin->isActive(cfg) ) { up = TRUE; if ( firstStart ) plugin->start( cfg ); } if ( plugin->isAvailable(cfg) ) available.append(*it); } } // Try to work around unreproducible bug whereby // the netmon applet shows wrong state. bool reannounce = wait<0; if ( available != pavailable || reannounce ) { QCopEnvelope e("QPE/Network", "available(QStringList)"); e << available; } if ( up != wasup || reannounce ) { QCopEnvelope("QPE/Network", up ? "up()" : "down()"); } } void start( const QString& file, const QString& password ) { if ( !current.isEmpty() ) stop(); current = QString::null; Config cfg(file, Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); bool started = FALSE; if ( plugin ) { cfg.setGroup("Properties"); if ( plugin->start(cfg,password) ) { Network::writeProxySettings( cfg ); current = file; wait=0; startTimer(400); started = TRUE; } } if ( !started ) { QCopEnvelope("QPE/Network", "failed()"); } } void stop() { bool stopped = FALSE; if ( !current.isEmpty() ) { Config cfg(current, Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); if ( plugin ) { cfg.setGroup("Properties"); if ( plugin->stop(cfg) ) { current = QString::null; wait=0; startTimer(400); stopped = TRUE; } } } if ( !stopped ) { QCopEnvelope("QPE/Network", "failed()"); } } void timerEvent(QTimerEvent*) { examineNetworks(); if ( wait >= 0 ) { if ( up == !current.isNull() ) { // done killTimers(); if ( up ) { startTimer(3000); // monitor link wait = -1; } } else { wait++; if ( wait == 600 ) { killTimers(); // forget about it after 240 s QCopEnvelope("QPE/Network", "failed()"); up = !current.isNull(); } } } else if ( !up ) { killTimers(); } } private: QStringList available; QString current; bool up; int wait; }; static NetworkServer* ns=0; /*! \internal */ QString Network::serviceName(const QString& service) { Config cfg(service, Config::File); cfg.setGroup("Info"); return cfg.readEntry("Name"); } /*! \internal */ QString Network::serviceType(const QString& service) { Config cfg(service, Config::File); cfg.setGroup("Info"); return cfg.readEntry("Type"); } /*! \internal */ bool Network::serviceNeedsPassword(const QString& service) { Config cfg(service,Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); cfg.setGroup("Properties"); return plugin ? plugin->needPassword(cfg) : FALSE; } /*! \internal */ bool Network::networkOnline() { return ns && ns->networkOnline(); } /*! \internal */ void Network::createServer(QObject* parent) { ns = new NetworkServer(parent); } /*! \internal */ int Network::addStateWidgets(QWidget* parent) { int n=0; QStringList l = Network::choices(); QVBoxLayout* vb = new QVBoxLayout(parent); for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { Config cfg(*it,Config::File); cfg.setGroup("Info"); QString type = cfg.readEntry("Type"); NetworkInterface* plugin = Network::loadPlugin(type); cfg.setGroup("Properties"); if ( plugin ) { QWidget* w; if ( (w=plugin->addStateWidget(parent,cfg)) ) { n++; vb->addWidget(w); } } } return n; } static QDict<NetworkInterface> *ifaces; /*! \internal */ NetworkInterface* Network::loadPlugin(const QString& type) { #ifndef QT_NO_COMPONENT if ( !ifaces ) ifaces = new QDict<NetworkInterface>; NetworkInterface *iface = ifaces->find(type); if ( !iface ) { QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; QLibrary lib(libfile); if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) return 0; ifaces->insert(type,iface); QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { QString lang = *it; QTranslator * trans = new QTranslator(qApp); QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; if ( trans->load( tfn )) qApp->installTranslator( trans ); else delete trans; } } return iface; #else return 0; #endif } #include "network.moc" #endif // QT_NO_COP diff --git a/library/networkinterface.cpp b/library/networkinterface.cpp index 2b5c77e..0ba773a 100644 --- a/library/networkinterface.cpp +++ b/library/networkinterface.cpp @@ -1,106 +1,104 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "networkinterface.h" #include "network.h" #include "config.h" #include <stdio.h> QString NetworkInterface::device( Config& cfg ) const { return cfg.readEntry("Device"); } bool NetworkInterface::isActive( Config& cfg ) const { QString dev = device(cfg); if ( dev.isEmpty() ) return FALSE; QString dev0 = dev+'0'; FILE* f; f = fopen("/proc/net/dev", "r"); if ( f ) { char line[1024]; char devname[80]; while ( fgets( line, 1024, f ) ) { if ( sscanf(line," %[^:]:", devname)==1 ) { if ( devname == dev || devname == dev0 ) { fclose(f); -#ifdef QWS Network::writeProxySettings( cfg ); -#endif return TRUE; } } } fclose(f); } return FALSE; } QString NetworkInterface::cardType( Config& cfg ) const { return cfg.readEntry("CardType"); } bool NetworkInterface::isAvailable( Config& cfg ) const { QString ct = cardType(cfg); if ( ct.isEmpty() ) return FALSE; FILE* f = fopen("/var/run/stab", "r"); if (!f) f = fopen("/var/state/pcmcia/stab", "r"); if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); if ( f ) { char line[1024]; char devtype[80]; while ( fgets( line, 1024, f ) ) { if ( sscanf(line,"%*d %s %*s", devtype )==1 ) { if ( ct == devtype ) { fclose(f); return TRUE; } } } fclose(f); } return FALSE; } bool NetworkInterface::start( Config& cfg, const QString& /*password*/ ) { return start(cfg); } bool NetworkInterface::needPassword( Config& ) const { return FALSE; } QWidget* NetworkInterface::addStateWidget( QWidget*, Config& ) const { return 0; } diff --git a/library/password.cpp b/library/password.cpp index 41b3358..4b22b65 100644 --- a/library/password.cpp +++ b/library/password.cpp @@ -1,335 +1,333 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "password.h" #include "config.h" #include "global.h" #include "backend/contact.h" #include <qlabel.h> #include <qlineedit.h> #include <qtextview.h> #include <qstring.h> #include <qapplication.h> #include <qfile.h> -#ifdef QWS #include <qwindowsystem_qws.h> -#endif #include <qdialog.h> #include <unistd.h> //for sleep #include "passwordbase_p.h" class PasswordDialog : public PasswordBase { Q_OBJECT public: PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~PasswordDialog(); void clear(); void setPrompt( const QString& ); signals: void passwordEntered( const QString& ); protected: bool eventFilter( QObject*, QEvent* ); void keyPressEvent( QKeyEvent * ); private: void input( QString ); friend class Password; QString text; }; extern "C" char *crypt(const char *key, const char *salt); static QString qcrypt(const QString& k, const char *salt) { return QString::fromUtf8(crypt(k.utf8(),salt)); } /* * Constructs a PasswordDialog which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl ) : PasswordBase( parent, name, fl ) { QRect desk = qApp->desktop()->geometry(); if ( desk.width() < 220 ) { QFont f( font() ); f.setPointSize( 18 ); setFont( f ); f.setPointSize( 12 ); prompt->setFont( f ); } button_0->installEventFilter( this ); button_1->installEventFilter( this ); button_2->installEventFilter( this ); button_3->installEventFilter( this ); button_4->installEventFilter( this ); button_5->installEventFilter( this ); button_6->installEventFilter( this ); button_7->installEventFilter( this ); button_8->installEventFilter( this ); button_9->installEventFilter( this ); button_OK->installEventFilter( this ); setFocus(); } /* * Destroys the object and frees any allocated resources */ PasswordDialog::~PasswordDialog() { // no need to delete child widgets, Qt does it all for us } /*! \reimp */ bool PasswordDialog::eventFilter( QObject*o, QEvent*e ) { if ( e->type() == QEvent::MouseButtonRelease ) { if ( o == button_OK ) { emit passwordEntered( text ); } else { QLabel *l = (QLabel*)o; input(l->text()); } } return FALSE; } /*! \reimp */ void PasswordDialog::keyPressEvent( QKeyEvent * ) { #if 0 if ( e->key() == Key_Enter || e->key() == Key_Return ) emit passwordEntered( text ); else input( e->text() ); #endif } /*! */ void PasswordDialog::input( QString c ) { text += c; display->setText( text ); } /*! */ void PasswordDialog::setPrompt( const QString& s ) { prompt->setText( s ); } void PasswordDialog::clear() { text = ""; input(""); } class PasswdDlg : public QDialog { public: PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE ) : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ), modl(modal) { passw = new PasswordDialog( this ); if ( fullscreen ) { QRect desk = qApp->desktop()->geometry(); setGeometry( 0, 0, desk.width(), desk.height() ); } connect( passw, SIGNAL(passwordEntered(const QString&)), this, SLOT(accept()) ); } void resizeEvent( QResizeEvent * ) { passw->resize( size() ); } void reset() { passw->clear(); } void execNonModal() { if ( !modl ) { reset(); showFullScreen(); do { qApp->enter_loop(); } while (result()!=1); } } void accept() { if ( !modl ) qApp->exit_loop(); QDialog::accept(); } PasswordDialog *passw; bool modl; }; class OwnerDlg : public QDialog { public: OwnerDlg( QWidget *parent, const char * name, Contact c, bool modal, bool fullscreen = FALSE ) : QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) { if ( fullscreen ) { QRect desk = qApp->desktop()->geometry(); setGeometry( 0, 0, desk.width(), desk.height() ); } // set up contents. QString text = "<H1>" + tr("Owner Information") + "</H1>"; text += c.toRichText(); tv = new QTextView(this); tv->setText(text); tv->viewport()->installEventFilter(this); } void resizeEvent( QResizeEvent * ) { tv->resize( size() ); } bool eventFilter(QObject *o, QEvent *e) { if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { accept(); return TRUE; } return QWidget::eventFilter(o, e); } void mousePressEvent( QMouseEvent * ) { accept(); } private: QTextView *tv; }; /*! Returns a crypted password entered by the user when prompted with \a prompt The returned value is QString::null if the user cancels the operation, or the empty string if the user enters no password (but confirms the dialog). */ QString Password::getPassword( const QString& prompt ) { PasswdDlg pd(0,0,TRUE); pd.passw->setPrompt( prompt ); pd.showMaximized(); int r = pd.exec(); if ( r == QDialog::Accepted ) { if (pd.passw->text.isEmpty()) return ""; else return qcrypt(pd.passw->text,"a0"); } else { return QString::null; } } /*! Prompt, fullscreen, for the user's passcode until they get it right. If \a at_poweron is TRUE, the dialog is only used if the user's preference request it at poweron; either way, the screen is always repainted by this function. (this functionality may move to the caller of this function). */ void Password::authenticate(bool at_poweron) { Config cfg("Security"); cfg.setGroup("Passcode"); QString passcode = cfg.readEntry("passcode"); if ( !passcode.isEmpty() && (!at_poweron || cfg.readNumEntry("passcode_poweron",0)) ) { // Do it as a fullscreen modal dialog PasswdDlg pd(0,0,TRUE,TRUE); // see if there is contact information. OwnerDlg *oi = 0; QString vfilename = Global::applicationFileName("addressbook", "businesscard.vcf"); if (QFile::exists(vfilename)) { Contact c; c = Contact::readVCard( vfilename )[0]; oi = new OwnerDlg(0, 0, c, TRUE, TRUE); } pd.reset(); pd.exec(); while (qcrypt(pd.passw->text, "a0") != passcode) { if (oi) oi->exec(); pd.reset(); pd.exec(); } } else if ( at_poweron ) { // refresh screen #### should probably be in caller // Not needed (we took away the screen blacking) //if ( qwsServer ) //qwsServer->refresh(); } } #include "password.moc" diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp index 214c721..9cbe92b 100644 --- a/library/qpedecoration_qws.cpp +++ b/library/qpedecoration_qws.cpp @@ -1,914 +1,912 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#ifdef QWS #define QTOPIA_INTERNAL_LANGLIST #include <qapplication.h> #include <qstyle.h> #include <qwidget.h> #include <qpainter.h> #include <qtimer.h> #include <qwhatsthis.h> #include "qcopenvelope_qws.h" #include "qpedecoration_qws.h" #include <qdialog.h> #include <qdrawutil.h> #include <qgfx_qws.h> #include "qpeapplication.h" #include "resource.h" #include "global.h" #include "qlibrary.h" #include "windowdecorationinterface.h" #include <qfile.h> #include <qsignal.h> #include <stdlib.h> extern QRect qt_maxWindowRect; #define WHATSTHIS_MODE #ifndef QT_NO_QWS_QPE_WM_STYLE #ifndef QT_NO_IMAGEIO_XPM /* XPM */ static const char * const qpe_close_xpm[] = { "16 16 3 1", " c None", ". c #FFFFFF", "+ c #000000", " ", " ", " ..... ", " ..+++++.. ", " .+++++++++. ", " .+..+++..+. ", " .++...+...++. ", " .+++.....+++. ", " .++++...++++. ", " .+++.....+++. ", " .++...+...++. ", " .+..+++..+. ", " .+++++++++. ", " ..+++++.. ", " ..... ", " "}; /* XPM */ static const char * const qpe_accept_xpm[] = { "16 16 3 1", " c None", ". c #FFFFFF", "+ c #000000", " ", " ", " ..... ", " ..+++++.. ", " .+++++++++. ", " .+++++++++. ", " .+++++++..++. ", " .++.+++...++. ", " .+...+...+++. ", " .+......++++. ", " .++....+++++. ", " .++..+++++. ", " .+++++++++. ", " ..+++++.. ", " ..... ", " "}; #endif // QT_NO_IMAGEIO_XPM class HackWidget : public QWidget { public: bool needsOk() { return (getWState() & WState_Reserved1 ) || (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); } }; static QImage scaleButton( const QImage &img, int height ) { if ( img.height() != 0 && img.height() != height ) { return img.smoothScale( img.width()*height/img.height(), height ); } else { return img; } } class TLWidget : public QWidget { public: QWSManager *manager() { return topData()->qwsManager; } QTLWExtra *topExtra() { return topData(); } void setWState( uint s ) { QWidget::setWState( s ); } void clearWState( uint s ) { QWidget::clearWState( s ); } }; QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) { wtTimer = new QTimer( this ); connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); } void QPEManager::updateActive() { QWidget *newActive = qApp->activeWindow(); if ( newActive && (QWidget*)active == newActive ) return; if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); } if ( newActive && ((TLWidget *)newActive)->manager() ) { active = newActive; ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); } else if ( !newActive ) { active = 0; } } int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) { QRect rect(w->geometry()); if ( decoration->region( w, rect, (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) return QPEDecoration::Help; for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) return (QWSDecoration::Region)i; } return QWSDecoration::None; } bool QPEManager::eventFilter( QObject *o, QEvent *e ) { QWSManager *mgr = (QWSManager *)o; QWidget *w = mgr->widget(); switch ( e->type() ) { case QEvent::MouseButtonPress: { pressTime = QTime::currentTime(); QPoint p = ((QMouseEvent*)e)->globalPos(); int inRegion = pointInQpeRegion( w, p ); #ifdef WHATSTHIS_MODE if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { QString text; switch ( inRegion ) { case QWSDecoration::Close: if ( ((HackWidget*)w)->needsOk() ) text = tr("Click to close this window, discarding changes."); else text = tr("Click to close this window."); break; case QWSDecoration::Minimize: text = tr("Click to close this window and apply changes."); break; case QWSDecoration::Maximize: if ( w->isMaximized() ) text = tr("Click to make this window moveable."); else text = tr("Click to make this window use all available screen area."); break; default: break; } QWhatsThis::leaveWhatsThisMode( text ); whatsThisTimeout(); helpState = 0; return true; } #endif if ( inRegion == QPEDecoration::Help ) { #ifdef WHATSTHIS_MODE wtTimer->start( 400, TRUE ); #endif helpState = QWSButton::Clicked|QWSButton::MouseOver; drawButton( w, QPEDecoration::Help, helpState ); return true; } } break; case QEvent::MouseButtonRelease: if ( helpState & QWSButton::Clicked ) { wtTimer->stop(); helpState = 0; drawButton( w, QPEDecoration::Help, helpState ); QPoint p = ((QMouseEvent*)e)->globalPos(); if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { decoration->help( w ); } return true; } break; case QEvent::MouseMove: if ( helpState & QWSButton::Clicked ) { int oldState = helpState; QPoint p = ((QMouseEvent*)e)->globalPos(); if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { helpState = QWSButton::Clicked|QWSButton::MouseOver; } else { helpState = 0; } if ( helpState != oldState ) drawButton( w, QPEDecoration::Help, helpState ); } break; default: break; } return QObject::eventFilter( o, e ); } void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) { QPainter painter(w); QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; painter.internalGfx()->setWidgetDeviceRegion( rgn ); painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); } void QPEManager::drawTitle( QWidget *w ) { QPainter painter(w); QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; painter.internalGfx()->setWidgetDeviceRegion( rgn ); painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); decoration->paint( &painter, w ); decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); decoration->paintButton(&painter, w, QWSDecoration::Close, 0); decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); } void QPEManager::whatsThisTimeout() { if ( !QWhatsThis::inWhatsThisMode() ) { if ( inWhatsThis ) { if ( whatsThis ) { QWidget *w = whatsThis; whatsThis = 0; drawTitle( w ); } wtTimer->stop(); } else { QWhatsThis::enterWhatsThisMode(); helpState = 0; updateActive(); if ( active ) { whatsThis = active; drawTitle( active ); // check periodically to see if we've left whats this mode wtTimer->start( 250 ); } } inWhatsThis = !inWhatsThis; } } //=========================================================================== static QImage *okImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); } return i; } static QImage *closeImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); } return i; } static QImage *helpImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); } return i; } static QImage *maximizeImage( int th ) { static QImage *i = 0; if ( !i || i->height() != th ) { delete i; i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); } return i; } int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const { switch ( m ) { case TitleHeight: if ( QApplication::desktop()->height() > 320 ) return 19; else return 15; case LeftBorder: case RightBorder: case TopBorder: case BottomBorder: return 4; case OKWidth: return okImage(metric(TitleHeight,wd))->width(); case CloseWidth: return closeImage(metric(TitleHeight,wd))->width(); case HelpWidth: return helpImage(metric(TitleHeight,wd))->width(); case MaximizeWidth: return maximizeImage(metric(TitleHeight,wd))->width(); case CornerGrabSize: return 16; } return 0; } void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const { int th = metric( TitleHeight, wd ); QRect r = wd->rect; switch ( a ) { case Border: { const QColorGroup &cg = wd->palette.active(); qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), r.y()-th-metric(TopBorder,wd), r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), cg, FALSE, &cg.brush(QColorGroup::Background)); } break; case Title: { const QColorGroup &cg = wd->palette.active(); QBrush titleBrush; QPen titleLines; if ( wd->flags & WindowData::Active ) { titleBrush = cg.brush(QColorGroup::Highlight); titleLines = titleBrush.color().dark(); } else { titleBrush = cg.brush(QColorGroup::Background); titleLines = titleBrush.color(); } p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); p->setPen( titleLines ); for ( int i = r.y()-th; i < r.y(); i += 2 ) p->drawLine( r.left(), i, r.right(), i ); } break; case TitleText: p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), th, QPainter::AlignVCenter, wd->caption); break; } } void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const { QImage *img = 0; switch ( b ) { case OK: img = okImage(metric(TitleHeight,wd)); break; case Close: img = closeImage(metric(TitleHeight,wd)); break; case Help: img = helpImage(metric(TitleHeight,wd)); break; case Maximize: img = maximizeImage(metric(TitleHeight,wd)); break; } if ( img ) { if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) p->drawImage(x+2, y+2, *img); else p->drawImage(x+1, y+1, *img); } } QRegion WindowDecorationInterface::mask( const WindowData *wd ) const { int th = metric(TitleHeight,wd); QRect rect( wd->rect ); QRect r(rect.left() - metric(LeftBorder,wd), rect.top() - th - metric(TopBorder,wd), rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); return QRegion(r) - rect; } class DefaultWindowDecoration : public WindowDecorationInterface { public: DefaultWindowDecoration() : ref(0) {} QString name() const { return "Default"; } QPixmap icon() const { return QPixmap(); } QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { *iface = 0; if ( uuid == IID_QUnknown ) *iface = this; else if ( uuid == IID_WindowDecoration ) *iface = this; if ( *iface ) (*iface)->addRef(); return QS_OK; } Q_REFCOUNT private: ulong ref; }; static WindowDecorationInterface *wdiface = 0; static QLibrary *wdlib = 0; //=========================================================================== QPEDecoration::QPEDecoration() : QWSDefaultDecoration() { if ( wdlib ) { wdiface->release(); wdlib->unload(); delete wdlib; wdlib = 0; } else { delete wdiface; } wdiface = new DefaultWindowDecoration; helpFile = QString(qApp->argv()[0]) + ".html"; QStringList helpPath = Global::helpPath(); helpExists = FALSE; for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { helpExists = QFile::exists( *it + "/" + helpFile ); qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); } qpeManager = new QPEManager( this ); } QPEDecoration::QPEDecoration( const QString &plugin ) : QWSDefaultDecoration() { if ( wdlib ) { wdiface->release(); wdlib->unload(); delete wdlib; wdlib = 0; } else { delete wdiface; } WindowDecorationInterface *iface = 0; QString path = QPEApplication::qpeDir() + "/plugins/decorations"; QLibrary *lib = new QLibrary( path + "/" + plugin ); if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { wdiface = iface; wdlib = lib; } else { delete lib; wdiface = new DefaultWindowDecoration; } helpFile = QString(qApp->argv()[0]) + ".html"; QStringList helpPath = Global::helpPath(); helpExists = FALSE; for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { helpExists = QFile::exists( *it + "/" + helpFile ); qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); } qpeManager = new QPEManager( this ); } QPEDecoration::~QPEDecoration() { delete qpeManager; } const char **QPEDecoration::menuPixmap() { return (const char **)0; } const char **QPEDecoration::closePixmap() { return (const char **)qpe_close_xpm; } const char **QPEDecoration::minimizePixmap() { return (const char **)qpe_accept_xpm; } const char **QPEDecoration::maximizePixmap() { return (const char **)0; } const char **QPEDecoration::normalizePixmap() { return (const char **)0; } int QPEDecoration::getTitleHeight( const QWidget *w ) { WindowDecorationInterface::WindowData wd; windowData( w, wd ); return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); } /* If rect is empty, no frame is added. (a hack, really) */ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) { qpeManager->updateActive(); WindowDecorationInterface::WindowData wd; windowData( widget, wd ); wd.rect = rect; int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); QRegion region; switch ((int)type) { case Menu: break; case Maximize: if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); int left = rect.right() - maximizeWidth - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) left -= okWidth; QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); region = r; } break; case Minimize: if ( ((HackWidget *)widget)->needsOk() ) { QRect r(rect.right() - okWidth, rect.top() - titleHeight, okWidth, titleHeight); if (r.left() > rect.left() + titleHeight) region = r; } break; case Close: { int left = rect.right() - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) left -= okWidth; QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); region = r; } break; case Title: if ( !widget->isMaximized() ) { int width = rect.width() - helpWidth - closeWidth; if ( ((HackWidget *)widget)->needsOk() ) width -= okWidth; QRect r(rect.left()+helpWidth, rect.top() - titleHeight, width, titleHeight); if (r.width() > 0) region = r; } break; case Help: if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { QRect r(rect.left(), rect.top() - titleHeight, helpWidth, titleHeight); region = r; } break; case Top: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); region = m & QRect( br.left()+grab, br.top(), br.width()-2*grab, b ); } break; case Left: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); region = m & QRect( br.left(), br.top()+grab, b, br.height()-2*grab ); } break; case Right: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); region = m & QRect( rect.right(), br.top()+grab, b, br.height()-2*grab ); } break; case Bottom: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); region = m & QRect( br.left()+grab, rect.bottom(), br.width()-2*grab, b ); } break; case TopLeft: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); QRegion crgn( br.left(), br.top(), grab, tb ); crgn |= QRect( br.left(), br.top(), lb, grab ); region = m & crgn; } break; case TopRight: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); QRegion crgn( br.right()-grab, br.top(), grab, tb ); crgn |= QRect( br.right()-rb, br.top(), rb, grab ); region = m & crgn; } break; case BottomLeft: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); } break; case BottomRight: if ( !widget->isMaximized() ) { QRegion m = wdiface->mask(&wd); QRect br = m.boundingRect(); region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); } break; case All: if ( widget->isMaximized() ) region = QWSDefaultDecoration::region(widget, rect, type); else region = wdiface->mask(&wd) - rect; break; default: region = QWSDefaultDecoration::region(widget, rect, type); break; } return region; } void QPEDecoration::paint(QPainter *painter, const QWidget *widget) { WindowDecorationInterface::WindowData wd; windowData( widget, wd ); int titleWidth = getTitleWidth(widget); int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); QRect rect(widget->rect()); // title bar rect QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); #ifndef QT_NO_PALETTE QRegion oldClip = painter->clipRegion(); painter->setClipRegion( oldClip - QRegion( tr ) ); // reduce flicker wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); painter->setClipRegion( oldClip ); if (titleWidth > 0) { const QColorGroup &cg = widget->palette().active(); QBrush titleBrush; QPen titlePen; if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { titleBrush = cg.brush(QColorGroup::Highlight); titlePen = cg.color(QColorGroup::HighlightedText); } else { titleBrush = cg.brush(QColorGroup::Background); titlePen = cg.color(QColorGroup::Text); } wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); // Draw caption painter->setPen(titlePen); QFont f( QApplication::font() ); f.setWeight( QFont::Bold ); painter->setFont(f); wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); } #endif //QT_NO_PALETTE paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); } void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, QWSDecoration::Region type, int state) { WindowDecorationInterface::Button b; switch ((int)type) { case Close: b = WindowDecorationInterface::Close; break; case Minimize: if ( ((HackWidget *)w)->needsOk() ) b = WindowDecorationInterface::OK; else if ( helpExists ) b = WindowDecorationInterface::Help; else return; break; case Help: b = WindowDecorationInterface::Help; break; case Maximize: b = WindowDecorationInterface::Maximize; break; default: return; } WindowDecorationInterface::WindowData wd; windowData( w, wd ); int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); QRect rect(w->rect()); QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); QRect brect(region(w, w->rect(), type).boundingRect()); const QColorGroup &cg = w->palette().active(); if ( wd.flags & WindowDecorationInterface::WindowData::Active ) painter->setPen( cg.color(QColorGroup::HighlightedText) ); else painter->setPen( cg.color(QColorGroup::Text) ); QRegion oldClip = painter->clipRegion(); painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); painter->setClipRegion( oldClip ); } //#define QPE_DONT_SHOW_TITLEBAR void QPEDecoration::maximize( QWidget *widget ) { #ifdef QPE_DONT_SHOW_TITLEBAR if ( !widget->inherits( "QDialog" ) ) { widget->setGeometry( qt_maxWindowRect ); } else #endif { QWSDecoration::maximize( widget ); } } #ifndef QT_NO_DIALOG class HackDialog : public QDialog { public: void acceptIt() { if ( isA( "QMessageBox" ) ) qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); else accept(); } }; #endif void QPEDecoration::minimize( QWidget *widget ) { #ifndef QT_NO_DIALOG // We use the minimize button as an "accept" button. if ( widget->inherits( "QDialog" ) ) { HackDialog *d = (HackDialog *)widget; d->acceptIt(); } #endif else if ( ((HackWidget *)widget)->needsOk() ) { QSignal s; s.connect( widget, SLOT( accept() ) ); s.activate(); } else { help( widget ); } } void QPEDecoration::help( QWidget *w ) { if ( helpExists ) { Global::execute( "helpbrowser", helpFile ); } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { QWhatsThis::enterWhatsThisMode(); QWhatsThis::leaveWhatsThisMode( qApp->tr( "<Qt>Comprehensive help is not available for this application, " "however there is context-sensitive help.<p>To use context-sensitive help:<p>" "<ol><li>click and hold the help button." "<li>when the title bar shows <b>What's this...</b>, " "click on any control.</ol></Qt>" ) ); } } void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const { wd.rect = w->rect(); if ( qpeManager->whatsThisWidget() == w ) wd.caption = qApp->tr("What's this..." ); else wd.caption = w->caption(); wd.palette = qApp->palette(); wd.flags = 0; wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; const QWidget *active = qpeManager->activeWidget(); wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; wd.reserved = 1; } /* #ifndef QT_NO_POPUPMENU QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) { return 0; } #endif */ #endif // QT_NO_QWS_QPE_WM_STYLE -#endif diff --git a/library/tzselect.cpp b/library/tzselect.cpp index 9436867..2e5a433 100644 --- a/library/tzselect.cpp +++ b/library/tzselect.cpp @@ -1,275 +1,271 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #define QTOPIA_INTERNAL_TZSELECT_INC_LOCAL #include "tzselect.h" #include "resource.h" #include "global.h" #include "config.h" #include <qtoolbutton.h> #include <qfile.h> #include <stdlib.h> -#ifdef Q_WS_QWS #include <qcopchannel_qws.h> -#endif class TimeZoneSelectorPrivate { public: TimeZoneSelectorPrivate() : includeLocal(FALSE) {} bool includeLocal; }; TZCombo::TZCombo( QWidget *p, const char* n ) : QComboBox( p, n ) { updateZones(); // check to see if TZ is set, if it is set the current item to that QString tz = getenv("TZ"); if (parent()->inherits("TimeZoneSelector")) { if ( ((TimeZoneSelector *)parent())->localIncluded() ) { // overide to the 'local' type. tz = "None"; } } if ( !tz.isNull() ) { int n = 0, index = 0; for ( QStringList::Iterator it=identifiers.begin(); it!=identifiers.end(); ++it) { if ( *it == tz ) index = n; n++; } setCurrentItem(index); } else { setCurrentItem(0); } // listen on QPE/System -#if defined(Q_WS_QWS) #if !defined(QT_NO_COP) QCopChannel *channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); #endif -#endif } TZCombo::~TZCombo() { } void TZCombo::updateZones() { QString cur = currentText(); clear(); identifiers.clear(); int curix=0; QString tz = getenv("TZ"); bool tzFound = FALSE; Config cfg("CityTime"); cfg.setGroup("TimeZones"); int listIndex = 0; if (parent()->inherits("TimeZoneSelector")) { if ( ((TimeZoneSelector *)parent())->localIncluded() ) { // overide to the 'local' type. identifiers.append( "None" ); insertItem( tr("None") ); if ( cur == tr("None")) curix = 0; listIndex++; } } int cfgIndex = 0; while (1) { QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); if ( zn.isNull() ) break; if ( zn == tz ) tzFound = TRUE; QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); identifiers.append(zn); insertItem(nm); if ( nm == cur ) curix = listIndex; ++cfgIndex; ++listIndex; } if ( !listIndex ) { QStringList list = timezoneDefaults(); for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { QString zn = *it; QString nm = *++it; if ( zn == tz ) tzFound = TRUE; if ( nm == cur ) curix = listIndex; identifiers.append(zn); insertItem(nm); ++listIndex; } } for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { insertItem(*it); identifiers.append(*it); if ( *it == cur ) curix = listIndex; ++listIndex; } if ( !tzFound && !tz.isEmpty()) { int i = tz.find( '/' ); QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); identifiers.append(tz); insertItem(nm); if ( nm == cur ) curix = listIndex; ++listIndex; } setCurrentItem(curix); } void TZCombo::keyPressEvent( QKeyEvent *e ) { // ### should popup() in Qt 3.0 (it's virtual there) // updateZones(); QComboBox::keyPressEvent(e); } void TZCombo::mousePressEvent(QMouseEvent*e) { // ### should popup() in Qt 3.0 (it's virtual there) // updateZones(); QComboBox::mousePressEvent(e); } QString TZCombo::currZone() const { return identifiers[currentItem()]; } void TZCombo::setCurrZone( const QString& id ) { for (int i=0; i< count(); i++) { if ( identifiers[i] == id ) { setCurrentItem(i); return; } } insertItem(id); setCurrentItem( count() - 1); identifiers.append(id); extras.append(id); } void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) { if ( msg == "timeZoneListChange()" ) { updateZones(); } } TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : QHBox(p,n) { d = new TimeZoneSelectorPrivate(); // build the combobox before we do any updates... cmbTz = new TZCombo( this, "timezone combo" ); cmdTz = new QToolButton( this, "timezone button" ); cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); cmdTz->setMaximumSize( cmdTz->sizeHint() ); // set up a connection to catch a newly selected item and throw our // signal QObject::connect( cmbTz, SIGNAL( activated( int ) ), this, SLOT( slotTzActive( int ) ) ); QObject::connect( cmdTz, SIGNAL( clicked() ), this, SLOT( slotExecute() ) ); } TimeZoneSelector::~TimeZoneSelector() { } void TimeZoneSelector::setLocalIncluded(bool b) { d->includeLocal = b; cmbTz->updateZones(); } bool TimeZoneSelector::localIncluded() const { return d->includeLocal; } QString TimeZoneSelector::currentZone() const { return cmbTz->currZone(); } void TimeZoneSelector::setCurrentZone( const QString& id ) { cmbTz->setCurrZone( id ); } void TimeZoneSelector::slotTzActive( int ) { emit signalNewTz( cmbTz->currZone() ); } void TimeZoneSelector::slotExecute( void ) { // execute the world time application... Global::execute( "citytime" ); } QStringList timezoneDefaults( void ) { QStringList tzs; // load up the list just like the file format (citytime.cpp) tzs.append( "America/New_York" ); tzs.append( "New York" ); tzs.append( "America/Los_Angeles" ); tzs.append( "Los Angeles" ); tzs.append( "Australia/Brisbane" ); tzs.append( "Brisbane" ); tzs.append( "Europe/Berlin" ); tzs.append( "Berlin" ); tzs.append( "Asia/Tokyo" ); tzs.append( "Tokyo" ); tzs.append( "America/Denver" ); tzs.append( "Denver" ); return tzs; } |