-rw-r--r-- | library/applnk.cpp | 16 | ||||
-rw-r--r-- | library/backend/categories.cpp | 9 | ||||
-rw-r--r-- | library/backend/categories.h | 2 | ||||
-rw-r--r-- | library/backend/event.cpp | 4 | ||||
-rw-r--r-- | library/backend/palmtoprecord.h | 12 | ||||
-rw-r--r-- | library/datebookdb.cpp | 12 | ||||
-rw-r--r-- | library/finddialog.cpp | 7 | ||||
-rw-r--r-- | library/global.cpp | 28 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 3 | ||||
-rw-r--r-- | library/storage.cpp | 6 |
10 files changed, 65 insertions, 34 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp index 35822dd..00030e8 100644 --- a/library/applnk.cpp +++ b/library/applnk.cpp @@ -207,257 +207,273 @@ public: \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. */ +/*! + \fn bool AppLnk::fileKnown() const + + If the with the AppLnk associated file is not equal to QString::null +*/ +/*! + \fn bool AppLnk::linkFileKnown()const + + The filename of the AppLnk +*/ +/*! + \fn void AppLnk::setRotation( const QString& ) + + The default rotation of the associated application. This + function is included inline for binary compatible issues +*/ /*! 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 ( this == © ) return *this; 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( diff --git a/library/backend/categories.cpp b/library/backend/categories.cpp index 2e84089..cce9f38 100644 --- a/library/backend/categories.cpp +++ b/library/backend/categories.cpp @@ -362,257 +362,257 @@ bool Categories::removeCategory( const QString &appname, Removes the \a uid from the application group \a appname. Returns TRUE if success, FALSE if not found. */ bool Categories::removeCategory( const QString &appname, int uid ) { QMap< QString, CategoryGroup >::Iterator appIt = mAppCats.find( appname ); if ( appIt != mAppCats.end() ) { CategoryGroup &cats = *appIt; if ( cats.remove( uid ) ) { emit categoryRemoved( *this, appname, uid ); return TRUE; } } return FALSE; } /*! Removes the global category \a catname. Returns TRUE if success, FALSE if not found. */ bool Categories::removeGlobalCategory( const QString &catname ) { int uid = mGlobalCats.id( catname ); if ( mGlobalCats.remove( uid ) ) { emit categoryRemoved( *this, QString::null, uid ); return TRUE; } return FALSE; } /*! Removes the global category \a uid. Returns TRUE if success, FALSE if not found. */ bool Categories::removeGlobalCategory( int uid ) { if ( mGlobalCats.remove( uid ) ) { emit categoryRemoved( *this, QString::null, uid ); return TRUE; } return FALSE; } /*! Returns the sorted list of all categories that are associated with the \a app. If \a includeGlobal is TRUE then the returned categories will include the global category items. */ QStringList Categories::labels( const QString &app, bool includeGlobal, ExtraLabels extra ) const { QMap< QString, CategoryGroup >::ConstIterator appIt = mAppCats.find( app ); QStringList cats; if ( appIt != mAppCats.end() ) cats += (*appIt).labels(); //else qDebug("Categories::labels didn't find app %s", app.latin1() ); if ( includeGlobal ) cats += mGlobalCats.labels(); cats.sort(); switch ( extra ) { case NoExtra: break; case AllUnfiled: cats.append( tr("All") ); cats.append( tr("Unfiled") ); break; case AllLabel: cats.append( tr("All") ); break; case UnfiledLabel: cats.append( tr("Unfiled") ); break; } return cats; } /*! Returns the label associated with the id */ QString Categories::label( const QString &app, int id ) const { if ( mGlobalCats.contains( id ) ) return mGlobalCats.label( id ); QMap< QString, CategoryGroup >::ConstIterator appIt = mAppCats.find( app ); if ( appIt == mAppCats.end() ) return QString::null; return (*appIt).label( id ); } /*! Returns a single string associated with \a catids for display in a combobox or any area that requires one string. If \a catids are empty then "Unfiled" will be returned. If multiple categories are assigned then the behavior depends on the DisplaySingle type. If \a display is set to ShowMulti then " (multi)" appended to the first string. If \a display is set to ShowAll, then a space seperated string is returned with all categories. If ShowFirst is set, the just the first string is returned. */ QString Categories::displaySingle( const QString &app, const QArray<int> &catids, DisplaySingle display ) const { QStringList strs = labels( app, catids ); if ( !strs.count() ) return tr("Unfiled"); strs.sort(); QString r; if ( strs.count() > 1 ) { switch ( display ) { case ShowFirst: r = strs.first(); break; case ShowMulti: r = strs.first() + tr(" (multi.)"); break; case ShowAll: r = strs.join(" "); break; } } - else r = strs.first(); + else r = strs.first(); return r; } /*! Returns all ids associated with the application CategoryGroup \a app and the passed in \a labels in that group. */ QArray<int> Categories::ids( const QString &app, const QStringList &labels) const { QArray<int> results; QStringList::ConstIterator it; int i; for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) { int value = id( app, *it ); if ( value != 0 ) { int tmp = results.size(); results.resize( tmp + 1 ); results[ tmp ] = value; } } return results; } /*! Returns the id associated with the app. If the id is not found in the application CategoryGroup, then it searches the global CategoryGroup. If it is not found it either, 0 is returned. */ int Categories::id( const QString &app, const QString &cat ) const { if ( cat == tr("Unfiled") || cat.contains( tr(" (multi.)") ) ) return 0; int uid = mGlobalCats.id( cat ); if ( uid != 0 ) return uid; return mAppCats[app].id( cat ); } /*! Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName is not found, or if \a newName conflicts with an existing category in the CategoryGroup. It will first search the CategoryGroup associated with \a appname and if not found it will try to replace in global CategoryGroup. */ bool Categories::renameCategory( const QString &appname, const QString &oldName, const QString &newName ) { QMap< QString, CategoryGroup >::Iterator appIt = mAppCats.find( appname ); if ( appIt != mAppCats.end() ) { CategoryGroup &cats = *appIt; int id = cats.id( oldName ); if ( id != 0 && cats.rename( id, newName ) ) { emit categoryRenamed( *this, appname, id ); return TRUE; } } return renameGlobalCategory( oldName, newName ); } /*! Return TRUE if renaming succeeded; FALSE if \a appname or \a oldName is not found, or if \a newName conflicts with an existing category in the CategoryGroup. This function will only rename categories found in the global CategoryGroup. */ bool Categories::renameGlobalCategory( const QString &oldName, const QString &newName ) { int uid = mGlobalCats.id( oldName ); if ( uid != 0 && mGlobalCats.rename( uid, newName ) ) { emit categoryRenamed( *this, QString::null, uid ); return TRUE; } return FALSE; } /*! Changes the grouping of a category. If a category was global and \a global is set to TRUE, then the \a catname will be moved to the \a appname group. */ void Categories::setGlobal( const QString &appname, const QString &catname, bool global ) { // if in global and should be in app; then move it if ( mGlobalCats.contains( catname ) && !global ) { mGlobalCats.remove( catname ); addCategory( appname, catname ); return ; } // if in app and should be in global, then move it if ( !global ) return; if ( removeCategory( appname, catname, FALSE ) ) addGlobalCategory( catname ); } /*! Returns TRUE if the \a catname is in the global CategoryGroup, FALSE if not. */ bool Categories::isGlobal( const QString &catname ) const { return mGlobalCats.contains( catname ); } /*! Returns true if the \a catname is associated with any CategoryGroup, including global. */ bool Categories::exists( const QString &catname ) const { if ( isGlobal(catname) ) return TRUE; for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) if ( exists( appsIt.key(), catname ) ) return TRUE; @@ -723,214 +723,209 @@ bool Categories::load( const QString &fname ) int len = data.length(); // QTime t; // t.start(); QString name; QString id; QString app; int i = 0; while ( (i = data.find( "<Category ", i)) != -1 ) { i += 10; name = QString::null; app = QString::null; while ( 1 ) { // skip white space while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) i++; // if at the end, then done if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) break; // we have another attribute read it. int j = i; while ( j < len && uc[j] != '=' ) j++; QString attr = QConstString( uc+i, j-i ).string(); i = ++j; // skip = while ( i < len && uc[i] != '"' ) i++; j = ++i; while ( j < len && uc[j] != '"' ) j++; QString value = Qtopia::plainString( QConstString( uc+i, j-i ).string() ); i = j + 1; // qDebug("attr='%s' value='%s'", attr.latin1(), value.latin1() ); if ( attr == "id" ) id = value; else if ( attr == "app" ) app = value; else if ( attr == "name" ) name = value; } if ( name.isNull() || id.isNull() ) { qWarning("No name or id in the category"); continue; } if ( app.isNull() ) mGlobalCats.add( id.toInt(), name ); else mAppCats[ app ].add( id.toInt(), name ); } return TRUE; } /*! Clear the categories in memory. Equivelent to creating an empty Categories object. */ void Categories::clear() { mGlobalCats.clear(); mAppCats.clear(); } /*! Dump the contents to standard out. Used for debugging only. */ void Categories::dump() const { qDebug("\tglobal categories = %s", mGlobalCats.labels().join(", ").latin1() ); for ( QMap<QString, CategoryGroup>::ConstIterator appsIt = mAppCats.begin(); appsIt != mAppCats.end(); ++appsIt ) { const QString &app = appsIt.key(); QStringList appcats = (*appsIt).labels(); qDebug("\tapp = %s\tcategories = %s", app.latin1(), appcats.join(", ").latin1() ); } } QStringList CheckedListView::checked() const { QStringList strs; for ( QCheckListItem *i = (QCheckListItem *) firstChild(); i; i = (QCheckListItem *)i->nextSibling() ) if ( i->isOn() ) strs += i->text( 0 ); return strs; } void CheckedListView::addCheckableList( const QStringList &options ) { for ( QStringList::ConstIterator it = options.begin(); it != options.end(); ++it ) { (void) new QCheckListItem( this, *it, QCheckListItem::CheckBox ); } } void CheckedListView::setChecked( const QStringList &checked ) { // iterate over all items bool showingChecked = FALSE; for ( QCheckListItem *i = (QCheckListItem *) firstChild(); i; i = (QCheckListItem *)i->nextSibling() ) // see if the item should be checked by searching the // checked list if ( checked.find( i->text( 0 ) ) != checked.end() ) { i->setOn( TRUE ); // make sure it is showing at least one checked item if ( !showingChecked ) { ensureItemVisible( i ); showingChecked = TRUE; } } else i->setOn( FALSE ); } /*! \fn Categories &Categories::operator= ( const Categories &c ) Performs deep copy. */ -/*! \fn QStringList Categories::labels( const QString & app, const QArray<int> &catids ) const - - Returns list of labels associated with the application and catids -*/ - /*! \fn QStringList Categories::globalCategories() const Returns list of all global category labels */ /*! \fn const QMap<QString, CategoryGroup> &Categories::appGroupMap() const Returns a map of application names to CategoryGroup. The CategoryGroup class defines a map of ids to category labels and category labels to ids. */ /*! \fn const CategoryGroup &Categories::globalGroup() const Returns the global CategoryGroup. The CategoryGroup class defines a map of ids to category labels and category labels to ids. */ /*! \fn void Categories::categoryAdded( const Categories &cats, const QString &appname, int uid) Emitted if a category is added. \a cats is a const reference to this object \a appname is the CategoryGroup application name that the category was added to or QString::null if it was global \a uid is the unique identifier associated with the added category -*/ +*/ /*! \fn void Categories::categoryRemoved( const Categories &cats, const QString &appname, int uid) Emitted if removed category is removed. \a cats is a const reference to this object \a appname is the CategoryGroup application name that the category was removed from or QString::null if it was the global CategoryGroup \a uid is the unique identifier associated with the removed category */ /*! \fn void Categories::categoryRenamed( const Categories &cats, const QString &appname, int uid) Emitted if \a uid in the \a appname CategoryGroup is renamed in \a cats object. \a cats is a const reference to this object \a appname is the CategoryGroup application name that the category was renamed in or QString::null if it was the global CategoryGroup \a uid is the unique identifier associated with the renamed category */ /*! \fn Categories::Categories( QObject *parent=0, const char *name = 0 ) Constructor for an empty Categories object. */ /*! \fn Categories::Categories( const Categories ©From ) Deep copy constructor */ /*! \fn Categories::~Categories() Empty destructor. Call save() before destruction if there are changes that need to be saved. */ /*! \fn CategoryGroup::clear() \internal */ /*! \fn const QMap<int, QString> &CategoryGroup::idMap() const Returns a const reference to the id to label QMap */ /*! \fn CategoryGroup::CategoryGroup() \internal */ /*! \fn CategoryGroup::CategoryGroup(const CategoryGroup &c) \internal */ diff --git a/library/backend/categories.h b/library/backend/categories.h index ba65ee3..d5b3669 100644 --- a/library/backend/categories.h +++ b/library/backend/categories.h @@ -1,216 +1,216 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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. ** **********************************************************************/ #ifndef QTPALMTOP_CATEGORIES_H #define QTPALMTOP_CATEGORIES_H #include <qstring.h> #include <qstringlist.h> #include <qmap.h> #include <qlistview.h> #include <qarray.h> #include "qpcglobal.h" #include "palmtopuidgen.h" class CategoryGroup; #if defined(QPC_TEMPLATEDLL) // MOC_SKIP_BEGIN template class QPC_EXPORT QMap<int, QString>; template class QPC_EXPORT QMap<QString, int>; template class QPC_EXPORT QMap< QString, CategoryGroup >; // MOC_SKIP_END #endif class QPC_EXPORT CategoryGroup { friend class Categories; public: CategoryGroup(): mIdLabelMap(), mLabelIdMap() { } CategoryGroup( const CategoryGroup &c ) : mIdLabelMap( c.mIdLabelMap), mLabelIdMap( c.mLabelIdMap ) { } void clear() { mIdLabelMap.clear(); mLabelIdMap.clear(); } int add( const QString &label ); bool add( int uid, const QString &label ); bool remove( const QString &label ); bool remove( int uid ); bool rename( int uid, const QString &newLabel ); bool rename( const QString &oldLabel, const QString &newLabel ); bool contains(int id) const; bool contains(const QString &label) const; /** Returns label associated with the uid or QString::null if * not found */ const QString &label(int id) const; /** Returns the uid associated with label or 0 if not found */ int id(const QString &label) const; /** Returns a sorted list of labels */ QStringList labels() const; QStringList labels( const QArray<int> &catids ) const; const QMap<int, QString> &idMap() const { return mIdLabelMap; } private: void insert( int uid, const QString &label ); QMap<int, QString> mIdLabelMap; QMap<QString, int> mLabelIdMap; static Qtopia::UidGen &uidGen() { return sUidGen; } static Qtopia::UidGen sUidGen; }; -/** Map from application name to categories */ +/* Map from application name to categories */ class QPC_EXPORT Categories : public QObject { Q_OBJECT public: Categories( QObject *parent=0, const char *name = 0 ) : QObject( parent, name ), mGlobalCats(), mAppCats() { } Categories( const Categories ©From ) : QObject( copyFrom.parent() ), mGlobalCats( copyFrom.mGlobalCats ), mAppCats( copyFrom.mAppCats ) { } virtual ~Categories() { } Categories &operator= ( const Categories &c ) { mAppCats = c.mAppCats; mGlobalCats = c.mGlobalCats; return *this; } void clear(); /** Add the category name as long as it doesn't already exist * locally or globally. Return UID if added, 0 if conflicts * (error). */ int addCategory( const QString &appname, const QString &catname); /** Add the category name as long as it doesn't already exist * locally or globally. Return UID if added, 0 if conflicts * (error). */ int addCategory( const QString &appname, const QString &catname, int uid); /** Add the global category just checking that it doesn't * already exist globally. Return UID if added, 0 if conflicts. */ int addGlobalCategory( const QString &catname ); /** Add the global category just checking that it doesn't * already exist globally. Return UID if added, 0 if conflicts. */ int addGlobalCategory( const QString &catname, int uid ); /** Removes the category from the application; if it is not found * in the application, then it removes it from the global list */ bool removeCategory( const QString &appName, const QString &catName, bool checkGlobal = TRUE); bool removeCategory( const QString &appName, int uid ); bool removeGlobalCategory( const QString &catName ); bool removeGlobalCategory( int uid ); QArray<int> ids( const QString &app, const QStringList &labels) const; /** Returns the id associated with the app */ int id( const QString &app, const QString &cat ) const; /** Returns the label associated with the id */ QString label( const QString &app, int id ) const; enum ExtraLabels { NoExtra, AllUnfiled, AllLabel, UnfiledLabel }; /** Returns the sorted list of all categories that are * associated with the app. * If includeGlobal parameter is TRUE then the returned * categories will include the global category items. * If extra = NoExtra, then * If extra = AllUnfiled, then All and Unfiled will be prepended to * the list * If extra = AllLabel, then All is prepended * If extra = UnfiledLabel, then Unfiled is prepended */ QStringList labels( const QString &app, bool includeGlobal = TRUE, ExtraLabels extra = NoExtra ) const; enum DisplaySingle { ShowMulti, ShowAll, ShowFirst }; /** Returns a single string associated with the cat ids for display in * a combobox or any area that requires one string. If catids are empty * then "Unfiled" will be returned. If multiple categories are assigned * then the behavior depends on the DisplaySingle type. * If /a display is set to ShowMulti then " (multi)" appended to the * first string. If /a display is set to ShowAll, then a space seperated * string is returned with all categories. If ShowFirst is returned, * the just the first string is returned. */ QString displaySingle( const QString &app, const QArray<int> &catids, DisplaySingle display ) const; QStringList globalCategories() const { return mGlobalCats.labels();} bool renameCategory( const QString &appname, const QString &oldName, const QString &newName ); bool renameGlobalCategory( const QString &oldName, const QString &newName ); void setGlobal( const QString &appname, const QString &catname, bool value ); bool isGlobal( const QString &catname ) const; /** Returns true if the catname is associated with any application */ bool exists( const QString &catname ) const; bool exists( const QString &appname, const QString &catname) const; bool save( const QString &fname ) const; bool load( const QString &fname ); // for debugging void dump() const; const QMap<QString, CategoryGroup> &appGroupMap() const{ return mAppCats; } const CategoryGroup &globalGroup() const { return mGlobalCats; } signals: /** emitted if added a category; * the second param is the application the category was added to * or null if global * the third param is the uid of the newly added category */ void categoryAdded( const Categories &, const QString &, int ); /** emitted if removed a category * the second param is the application the category was removed from * or null if global * the third param is the uid of the removed category */ void categoryRemoved( const Categories &, const QString &, int ); /** emitted if a category is renamed; the second param is the uid of * the removed category */ void categoryRenamed( const Categories &, const QString &, int ); private: CategoryGroup mGlobalCats; QMap< QString, CategoryGroup > mAppCats; }; diff --git a/library/backend/event.cpp b/library/backend/event.cpp index d906f19..4c24ab3 100644 --- a/library/backend/event.cpp +++ b/library/backend/event.cpp @@ -42,263 +42,263 @@ static void write( QString& buf, const Event::RepeatPattern &r ) buf += "Weekly"; break; case Event::MonthlyDay: buf += "MonthlyDay"; break; case Event::MonthlyDate: buf += "MonthlyDate"; break; case Event::Yearly: buf += "Yearly"; break; default: buf += "NoRepeat"; break; } buf += "\""; if ( r.days > 0 ) buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\""; if ( r.position != 0 ) buf += " rposition=\"" + QString::number( r.position ) + "\""; buf += " rfreq=\"" + QString::number( r.frequency ) + "\""; buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\""; if ( r.hasEndDate ) buf += " enddt=\"" + QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) ) + "\""; buf += " created=\"" + QString::number( r.createTime ) + "\""; } Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia ); /*! \class Event event.h \brief The Event class holds the data of a calendar event. This data includes descriptive data of the event and schedualing information. \ingroup qtopiaemb \ingroup qtopiadesktop */ /*! \class Event::RepeatPattern \class The Event::RepeatPattern class is internal. \internal */ /*! \enum Event::Days \internal */ /*! \enum Event::Type \internal */ /*! \enum Event::SoundTypeChoice This enum type defines what kind of sound is made when an alarm occurs for an event. The currently defined types are: <ul> <li>\c Silent - No sound is produced. <li>\c Loud - A loud sound is produced. </ul> */ /*! \fn bool Event::operator<( const Event & ) const \internal */ /*! \fn bool Event::operator<=( const Event & ) const \internal */ /*! \fn bool Event::operator!=( const Event & ) const \internal */ /*! \fn bool Event::operator>( const Event & ) const \internal */ /*! \fn bool Event::operator>=( const Event & ) const \internal */ /*! \enum Event::RepeatType This enum defines how a event will repeat, if at all. <ul> <li>\c NoRepeat - Event does not repeat. <li>\c Daily - Event occurs every n days. <li>\c Weekly - Event occurs every n weeks. <li>\c MonthlyDay - Event occurs every n months. Event will always occur in the same week and same day of week as the first event. <li>\c MonthlyDate - Event occurs every n months. Event will always occur on the same day of the month as the first event. <li>\c Yearly - Event occurs every n years. </ul> */ /*! \fn bool Event::isAllDay() const Returns TRUE if the event is an all day event. Otherwise returns FALSE. */ /*! \fn void Event::setAllDay(bool allday) If \a allday is TRUE, will set the event to be an all day event. Otherwise sets the event to not be an all day event. \warning This function may affect the start and end times of the event. */ /*! - \fn QDateTime Event::start() const + \fn QDateTime Event::start(bool) const Returns the start date and time of the first occurance of the event. */ /*! - \fn QDateTime Event::end() const + \fn QDateTime Event::end(bool) const Returns the end date and time of the first occurance of the event. */ /*! \fn time_t Event::startTime() const \internal */ /*! \fn time_t Event::endTime() const \internal */ /*! \fn void Event::setAlarm(int delay, SoundTypeChoice s) Sets the alarm delay of the event to \a delay and the sound type of the alarm to \a s. */ /*! \fn void Event::clearAlarm() Clears the alarm for the event. */ /*! \fn int Event::alarmDelay() const Returns the delay in minutes between the alarm for an event and the start of the event. */ /*! \fn Event::RepeatType Event::repeatType() const Returns the repeat pattern type for the event. \sa frequency() */ /*! \fn int Event::weekOffset() const Returns the number of weeks from the start of the month that this event occurs. */ /*! \fn QDate Event::repeatTill() const Returns the date that the event will continue to repeat until. If the event repeats forever the value returned is undefined. \sa repeatForever() */ /*! \fn bool Event::repeatForever() const Returns FALSE if there is a date set for the event to continue until. Otherwise returns TRUE. */ /*! \fn bool Event::doRepeat() const \internal */ /*! \fn bool Event::repeatOnWeekDay(int day) const Returns TRUE if the event has a RepeatType of Weekly and is set to occur on \a day each week. Otherwise returns FALSE. \sa QDate::dayName() */ /*! \fn void Event::setRepeatOnWeekDay(int day, bool enable) If \a enable is TRUE then sets the event to occur on \a day each week. Otherwise sets the event not to occur on \a day. \warning this function is only relavent for a event with RepeatType of Weekly. \sa QDate::dayName() */ /*! \fn int Event::frequency() const Returns how often the event repeats. \sa repeatType() */ /*! \fn void Event::setRepeatType(RepeatType t) Sets the repeat pattern type of the event to \a t. \sa setFrequency() */ /*! \fn void Event::setFrequency(int n) Sets how often the event occurs with in its repeat pattern. \sa setRepeatType() */ /*! \fn void Event::setRepeatTill(const QDate &d) Sets the event to repeat until \a d. */ /*! \fn void Event::setRepeatForever(bool enable) If \a enable is TRUE, sets the event to repeat forever. Otherwise sets the event to stop repeating at some date. \warning This function may affect the specific date the event will repeat diff --git a/library/backend/palmtoprecord.h b/library/backend/palmtoprecord.h index 72f7d1c..15cdd6a 100644 --- a/library/backend/palmtoprecord.h +++ b/library/backend/palmtoprecord.h @@ -1,95 +1,107 @@ /********************************************************************** ** 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. ** **********************************************************************/ #ifndef QTPALMTOP_RECORD_H #define QTPALMTOP_RECORD_H #include <qglobal.h> #include "qpcglobal.h" #include "palmtopuidgen.h" #include <qarray.h> #include <qmap.h> #if defined(QPC_TEMPLATEDLL) // MOC_SKIP_BEGIN QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<QString, QString>; // MOC_SKIP_END #endif class QRegExp; +/** + * @short Qtopia namespace + * The namespace of Qtopia + */ namespace Qtopia { class RecordPrivate; +/** + * @short The base class of all Records + * + * The base class for Records in Qtopia + * @see Task + * @see Event + * @see Contact + */ class QPC_EXPORT Record { public: Record() : mUid(0), mCats() { } Record( const Record &c ) : mUid( c.mUid ), mCats ( c.mCats ), customMap(c.customMap) { } virtual ~Record() { } Record &operator=( const Record &c ); virtual bool match( const QRegExp & ) const { return FALSE; } void setCategories( const QArray<int> &v ) { mCats = v; mCats.sort(); } void setCategories( int single ); const QArray<int> &categories() const { return mCats; } void reassignCategoryId( int oldId, int newId ) { int index = mCats.find( oldId ); if ( index >= 0 ) mCats[index] = newId; } int uid() const { return mUid; }; virtual void setUid( int i ) { mUid = i; uidGen().store( mUid ); } bool isValidUid() const { return mUid != 0; } void assignUid() { setUid( uidGen().generate() ); } virtual QString customField(const QString &) const; virtual void setCustomField(const QString &, const QString &); virtual void removeCustomField(const QString &); virtual bool operator == ( const Record &r ) const { return mUid == r.mUid; } virtual bool operator != ( const Record &r ) const { return mUid != r.mUid; } // convenience methods provided for loading and saving to xml static QString idsToString( const QArray<int> &ids ); // convenience methods provided for loading and saving to xml static QArray<int> idsFromString( const QString &str ); // for debugging static void dump( const QMap<int, QString> &map ); protected: virtual UidGen &uidGen() = 0; virtual QString customToXml() const; private: int mUid; QArray<int> mCats; QMap<QString, QString> customMap; RecordPrivate *d; }; } #endif diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index 0fedfa8..2f33255 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp @@ -1,202 +1,202 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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 <qasciidict.h> #include <qfile.h> #include <qmessagebox.h> #include <qstring.h> #include <qtextcodec.h> #include <qtextstream.h> #include <qtl.h> #include <qpe/alarmserver.h> #include <qpe/global.h> #include "datebookdb.h" #include <qpe/stringutil.h> #include <qpe/timeconversion.h> #include <errno.h> #include <stdlib.h> class DateBookDBPrivate { public: bool clean; // indcate whether we need to write to disk... }; // Helper functions static QString dateBookJournalFile() { QString str = getenv("HOME"); return QString( str +"/.caljournal" ); } static QString dateBookFilename() { return Global::applicationFileName("datebook","datebook.xml"); } /* Calculating the next event of a recuring event is actually computationally inexpensive, esp. compared to checking each day individually. There are bad worse cases for say the 29th of february or the 31st of some other months. However these are still bounded */ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) { // easy checks, first are we too far in the future or too far in the past? QDate tmpDate; int freq = e.repeatPattern().frequency; int diff, diff2, a; int iday, imonth, iyear; int dayOfWeek = 0; int firstOfWeek = 0; int weekOfMonth; - + if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from) return FALSE; if (e.start() >= from) { next = e.start(); return TRUE; } switch ( e.repeatPattern().type ) { case Event::Weekly: /* weekly is just daily by 7 */ /* first convert the repeatPattern.Days() mask to the next day of week valid after from */ dayOfWeek = from.dayOfWeek(); dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ /* this is done in case freq > 1 and from in week not for this round */ // firstOfWeek = 0; this is already done at decl. while(!((1 << firstOfWeek) & e.repeatPattern().days)) firstOfWeek++; /* there is at least one 'day', or there would be no event */ while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days)) dayOfWeek++; dayOfWeek = dayOfWeek % 7; /* the actual day of week */ dayOfWeek -= e.start().date().dayOfWeek() -1; firstOfWeek = firstOfWeek % 7; /* the actual first of week */ firstOfWeek -= e.start().date().dayOfWeek() -1; // dayOfWeek may be negitive now // day of week is number of days to add to start day freq *= 7; // FALL-THROUGH !!!!! case Event::Daily: // the add is for the possible fall through from weekly */ if(e.start().date().addDays(dayOfWeek) > from) { /* first week exception */ next = QDateTime(e.start().date().addDays(dayOfWeek), e.start().time()); if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) return FALSE; return TRUE; } /* if from is middle of a non-week */ diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq; diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq; if(diff != 0) diff = freq - diff; if(diff2 != 0) diff2 = freq - diff2; diff = QMIN(diff, diff2); next = QDateTime(from.addDays(diff), e.start().time()); if ( (next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate ) return FALSE; return TRUE; case Event::MonthlyDay: iday = from.day(); iyear = from.year(); imonth = from.month(); /* find equivelent day of month for this month */ dayOfWeek = e.start().date().dayOfWeek(); weekOfMonth = (e.start().date().day() - 1) / 7; /* work out when the next valid month is */ a = from.year() - e.start().date().year(); a *= 12; a = a + (imonth - e.start().date().month()); /* a is e.start()monthsFrom(from); */ if(a % freq) { a = freq - (a % freq); imonth = from.month() + a; if (imonth > 12) { imonth--; iyear += imonth / 12; imonth = imonth % 12; imonth++; } } /* imonth is now the first month after or on from that matches the frequency given */ /* find for this month */ tmpDate = QDate( iyear, imonth, 1 ); iday = 1; iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; iday += 7 * weekOfMonth; while (iday > tmpDate.daysInMonth()) { imonth += freq; if (imonth > 12) { imonth--; iyear += imonth / 12; imonth = imonth % 12; imonth++; } tmpDate = QDate( iyear, imonth, 1 ); /* these loops could go for a while, check end case now */ if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) return FALSE; iday = 1; iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; iday += 7 * weekOfMonth; } tmpDate = QDate(iyear, imonth, iday); if (tmpDate >= from) { next = QDateTime(tmpDate, e.start().time()); if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) return FALSE; return TRUE; } /* need to find the next iteration */ do { imonth += freq; if (imonth > 12) { imonth--; iyear += imonth / 12; @@ -336,519 +336,519 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) } } static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) { QDateTime now = QDateTime::currentDateTime(); if ( ev.hasRepeat() ) { QDateTime ralarm; if (nextOccurance(ev, now.date(), ralarm)) { ralarm = ralarm.addSecs(-ev.alarmTime()*60); if ( ralarm > now ) { when = ralarm; warn = ev.alarmTime(); } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); if ( ralarm > now ) { when = ralarm; warn = ev.alarmTime(); } } } } else { warn = ev.alarmTime(); when = ev.start().addSecs( -ev.alarmTime()*60 ); } return when > now; } static void addEventAlarm( const Event &ev ) { QDateTime when; int warn; if ( nextAlarm(ev,when,warn) ) AlarmServer::addAlarm( when, "QPE/Application/datebook", "alarm(QDateTime,int)", warn ); } static void delEventAlarm( const Event &ev ) { QDateTime when; int warn; if ( nextAlarm(ev,when,warn) ) AlarmServer::deleteAlarm( when, "QPE/Application/datebook", "alarm(QDateTime,int)", warn ); } DateBookDB::DateBookDB() { init(); } DateBookDB::~DateBookDB() { save(); eventList.clear(); repeatEvents.clear(); } //#### Why is this code duplicated in getEffectiveEvents ????? //#### Addendum. Don't use this function, lets faze it out if we can. QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) { QValueList<Event> tmpList; tmpList = getNonRepeatingEvents( from, to ); // check for repeating events... for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); it != repeatEvents.end(); ++it) { QDate itDate = from; QDateTime due; /* create a false end date, to short circuit on hard MonthlyDay recurences */ Event dummy_event = *it; Event::RepeatPattern r = dummy_event.repeatPattern(); if ( !r.hasEndDate || r.endDate() > to ) { r.setEndDate( to ); r.hasEndDate = TRUE; } dummy_event.setRepeat(TRUE, r); while (nextOccurance(dummy_event, itDate, due)) { if (due.date() > to) break; Event newEvent = *it; newEvent.setStart(due); newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); tmpList.append(newEvent); itDate = due.date().addDays(1); /* the next event */ } } qHeapSort(tmpList); return tmpList; } QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) { QValueList<Event> day = getEvents(start.date(),start.date()); QValueListConstIterator<Event> it; QDateTime dtTmp; QValueList<Event> tmpList; for (it = day.begin(); it != day.end(); ++it ) { dtTmp = (*it).start(TRUE); if ( dtTmp == start ) tmpList.append( *it ); } return tmpList; } //#### Why is this code duplicated in getEvents ????? QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, const QDate &to ) { QValueList<EffectiveEvent> tmpList; QValueListIterator<Event> it; EffectiveEvent effEv; QDateTime dtTmp, dtEnd; for (it = eventList.begin(); it != eventList.end(); ++it ) { - if (!(*it).isValidUid()) + if (!(*it).isValidUid()) (*it).assignUid(); // FIXME: Hack to restore cleared uids dtTmp = (*it).start(TRUE); dtEnd = (*it).end(TRUE); if ( dtTmp.date() >= from && dtTmp.date() <= to ) { Event tmpEv = *it; effEv.setEvent(tmpEv); effEv.setDate( dtTmp.date() ); effEv.setStart( dtTmp.time() ); if ( dtTmp.date() != dtEnd.date() ) effEv.setEnd( QTime(23, 59, 0) ); else effEv.setEnd( dtEnd.time() ); tmpList.append( effEv ); } // we must also check for end date information... if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { QDateTime dt = dtTmp.addDays( 1 ); dt.setTime( QTime(0, 0, 0) ); QDateTime dtStop; if ( dtEnd > to ) { dtStop = to; } else dtStop = dtEnd; while ( dt <= dtStop ) { Event tmpEv = *it; effEv.setEvent( tmpEv ); effEv.setDate( dt.date() ); if ( dt >= from ) { effEv.setStart( QTime(0, 0, 0) ); if ( dt.date() == dtEnd.date() ) effEv.setEnd( dtEnd.time() ); else effEv.setEnd( QTime(23, 59, 59) ); tmpList.append( effEv ); } dt = dt.addDays( 1 ); } } } // check for repeating events... QDateTime repeat; for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { - if (!(*it).isValidUid()) + if (!(*it).isValidUid()) (*it).assignUid(); // FIXME: Hack to restore cleared uids /* create a false end date, to short circuit on hard MonthlyDay recurences */ Event dummy_event = *it; int duration = (*it).start().date().daysTo( (*it).end().date() ); QDate itDate = from.addDays(-duration); Event::RepeatPattern r = dummy_event.repeatPattern(); if ( !r.hasEndDate || r.endDate() > to ) { r.setEndDate( to ); r.hasEndDate = TRUE; } dummy_event.setRepeat(TRUE, r); while (nextOccurance(dummy_event, itDate, repeat)) { if(repeat.date() > to) break; effEv.setDate( repeat.date() ); if ((*it).type() == Event::AllDay) { effEv.setStart( QTime(0,0,0) ); effEv.setEnd( QTime(23,59,59) ); } else { /* we only occur by days, not hours/minutes/seconds. Hence the actual end and start times will be the same for every repeated event. For multi day events this is fixed up later if on wronge day span */ effEv.setStart( (*it).start().time() ); effEv.setEnd( (*it).end().time() ); } if ( duration != 0 ) { // multi-day repeating events QDate sub_it = QMAX( repeat.date(), from ); QDate startDate = repeat.date(); QDate endDate = startDate.addDays( duration ); while ( sub_it <= endDate && sub_it <= to ) { EffectiveEvent tmpEffEv = effEv; Event tmpEv = *it; tmpEffEv.setEvent( tmpEv ); if ( sub_it != startDate ) tmpEffEv.setStart( QTime(0,0,0) ); if ( sub_it != endDate ) tmpEffEv.setEnd( QTime(23,59,59) ); tmpEffEv.setDate( sub_it ); tmpEffEv.setEffectiveDates( startDate, endDate ); tmpList.append( tmpEffEv ); sub_it = sub_it.addDays( 1 ); } itDate = endDate; } else { Event tmpEv = *it; effEv.setEvent( tmpEv ); tmpList.append( effEv ); itDate = repeat.date().addDays( 1 ); } } } qHeapSort( tmpList ); return tmpList; } QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) { QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); QValueListConstIterator<EffectiveEvent> it; QValueList<EffectiveEvent> tmpList; QDateTime dtTmp; for (it = day.begin(); it != day.end(); ++it ) { dtTmp = QDateTime( (*it).date(), (*it).start() ); // at the moment we don't have second granularity, be nice about that.. if ( QABS(dt.secsTo(dtTmp)) < 60 ) tmpList.append( *it ); } return tmpList; } void DateBookDB::addEvent( const Event &ev, bool doalarm ) { // write to the journal... saveJournalEntry( ev, ACTION_ADD, -1, false ); addJFEvent( ev, doalarm ); d->clean = false; } void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) { if ( doalarm && ev.hasAlarm() ) addEventAlarm( ev ); if ( ev.hasRepeat() ) repeatEvents.append( ev ); else eventList.append( ev ); } void DateBookDB::editEvent( const Event &old, Event &editedEv ) { int oldIndex=0; bool oldHadRepeat = old.hasRepeat(); Event orig; // write to the journal... if ( oldHadRepeat ) { if ( origRepeat( old, orig ) ) // should work always... oldIndex = repeatEvents.findIndex( orig ); } else oldIndex = eventList.findIndex( old ); saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); // Delete old event if ( old.hasAlarm() ) delEventAlarm( old ); if ( oldHadRepeat ) { - if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and + if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and // orig is initialized // assumption, when someone edits a repeating event, they // want to change them all, maybe not perfect, but it works // for the moment... repeatEvents.remove( orig ); } else removeRepeat( old ); } else { QValueList<Event>::Iterator it = eventList.find( old ); if ( it != eventList.end() ) eventList.remove( it ); } // Add new event if ( editedEv.hasAlarm() ) addEventAlarm( editedEv ); if ( editedEv.hasRepeat() ) repeatEvents.append( editedEv ); else eventList.append( editedEv ); d->clean = false; } void DateBookDB::removeEvent( const Event &ev ) { // write to the journal... saveJournalEntry( ev, ACTION_REMOVE, -1, false ); removeJFEvent( ev ); d->clean = false; } void DateBookDB::removeJFEvent( const Event&ev ) { if ( ev.hasAlarm() ) delEventAlarm( ev ); if ( ev.hasRepeat() ) { removeRepeat( ev ); } else { QValueList<Event>::Iterator it = eventList.find( ev ); if ( it != eventList.end() ) eventList.remove( it ); } } // also handles journaling... void DateBookDB::loadFile( const QString &strFile ) { - + QFile f( strFile ); if ( !f.open( IO_ReadOnly ) ) return; enum Attribute { FDescription = 0, FLocation, FCategories, FUid, FType, FAlarm, FSound, FRType, FRWeekdays, FRPosition, FRFreq, FRHasEndDate, FREndDate, FRStart, FREnd, FNote, FCreated, FAction, FActionKey, FJournalOrigHadRepeat }; QAsciiDict<int> dict( 97 ); dict.setAutoDelete( TRUE ); dict.insert( "description", new int(FDescription) ); dict.insert( "location", new int(FLocation) ); dict.insert( "categories", new int(FCategories) ); dict.insert( "uid", new int(FUid) ); dict.insert( "type", new int(FType) ); dict.insert( "alarm", new int(FAlarm) ); dict.insert( "sound", new int(FSound) ); dict.insert( "rtype", new int(FRType) ); dict.insert( "rweekdays", new int(FRWeekdays) ); dict.insert( "rposition", new int(FRPosition) ); dict.insert( "rfreq", new int(FRFreq) ); dict.insert( "rhasenddate", new int(FRHasEndDate) ); dict.insert( "enddt", new int(FREndDate) ); dict.insert( "start", new int(FRStart) ); dict.insert( "end", new int(FREnd) ); dict.insert( "note", new int(FNote) ); dict.insert( "created", new int(FCreated) ); dict.insert( "action", new int(FAction) ); dict.insert( "actionkey", new int(FActionKey) ); dict.insert( "actionorig", new int (FJournalOrigHadRepeat) ); - + QByteArray ba = f.readAll(); char* dt = ba.data(); int len = ba.size(); int currentAction, journalKey, origHadRepeat; // should be bool, but we need tri-state(not being used) int i = 0; char *point; // hack to get rid of segfaults after reading </DATEBOOK> while ( (dt+i != 0) && (( point = strstr( dt+i, "<event " ) ) != 0 )) { i = point - dt; // if we are reading in events in the general case, // we are just adding them, so let the actions represent that... currentAction = ACTION_ADD; journalKey = -1; origHadRepeat = -1; // some temporary variables for dates and times ... //int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0; //int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0; //int enddtY = 0, enddtM = 0, enddtD = 0; // ... for the alarm settings ... int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent; // ... and for the recurrence Event::RepeatPattern rp; Event e; i += 7; while( 1 ) { while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) ++i; if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) break; // we have another attribute, read it. int j = i; while ( j < len && dt[j] != '=' ) ++j; char *attr = dt+i; dt[j] = '\0'; i = ++j; // skip = while ( i < len && dt[i] != '"' ) ++i; j = ++i; bool haveAmp = FALSE; bool haveUtf = FALSE; while ( j < len && dt[j] != '"' ) { if ( dt[j] == '&' ) haveAmp = TRUE; if ( ((unsigned char)dt[j]) > 0x7f ) haveUtf = TRUE; ++j; } if ( i == j ) { // leave out empty attributes i = j + 1; continue; } QString value = haveUtf ? QString::fromUtf8( dt+i, j-i ) : QString::fromLatin1( dt+i, j-i ); if ( haveAmp ) value = Qtopia::plainString( value ); i = j + 1; //qDebug("attr='%s' value='%s'", attr.data(), value.latin1() ); int * find = dict[ attr ]; #if 1 if ( !find ) { // custom field e.setCustomField(attr, value); continue; } switch( *find ) { case FDescription: e.setDescription( value ); break; case FLocation: e.setLocation( value ); break; case FCategories: e.setCategories( Qtopia::Record::idsFromString( value ) ); break; case FUid: e.setUid( value.toInt() ); break; case FType: if ( value == "AllDay" ) e.setType( Event::AllDay ); else e.setType( Event::Normal ); break; case FAlarm: alarmTime = value.toInt(); break; case FSound: alarmSound = value == "loud" ? Event::Loud : Event::Silent; break; // recurrence stuff case FRType: if ( value == "Daily" ) rp.type = Event::Daily; else if ( value == "Weekly" ) rp.type = Event::Weekly; else if ( value == "MonthlyDay" ) rp.type = Event::MonthlyDay; else if ( value == "MonthlyDate" ) rp.type = Event::MonthlyDate; else if ( value == "Yearly" ) rp.type = Event::Yearly; else rp.type = Event::NoRepeat; break; case FRWeekdays: // QtopiaDesktop 1.6 sometimes creates 'rweekdays="0"' // when it goes mad. This causes datebook to crash.. (se) if ( value.toInt() != 0 ) rp.days = value.toInt(); else rp.days = 1; break; case FRPosition: rp.position = value.toInt(); break; case FRFreq: diff --git a/library/finddialog.cpp b/library/finddialog.cpp index d9f430a..ddf41a7 100644 --- a/library/finddialog.cpp +++ b/library/finddialog.cpp @@ -1,78 +1,85 @@ /********************************************************************** ** 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_FD #include "finddialog.h" #include "findwidget_p.h" #include <qlayout.h> #include <qpushbutton.h> +/*! + \class FindDialog finddialog.h + \brief A simple FindDialog + + A find dialog. FIXME!!!! + +*/ FindDialog::FindDialog( const QString &appName, QWidget *parent, const char *name, bool modal ) : QDialog( parent, name, modal ) { setCaption( tr("Find") ); QVBoxLayout *vb; vb = new QVBoxLayout( this ); fw = new FindWidget( appName, this, "Find Widget" ); vb->addWidget( fw ); QObject::connect( fw, SIGNAL(signalFindClicked(const QString&, bool,bool,int)), this, SIGNAL(signalFindClicked(const QString&, bool,bool,int)) ); QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&, bool,bool,int)), this, SIGNAL(signalFindClicked(const QString&, const QDate&,bool,bool,int)) ); d = 0; } FindDialog::~FindDialog() { } QString FindDialog::findText() const { return fw->findText(); } void FindDialog::setUseDate( bool show ) { fw->setUseDate( show ); } void FindDialog::setDate( const QDate &dt ) { fw->setDate( dt ); } void FindDialog::slotNotFound() { fw->slotNotFound(); } void FindDialog::slotWrapAround() { fw->slotWrapAround(); } diff --git a/library/global.cpp b/library/global.cpp index 68a3a75..ce39751 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -1,241 +1,241 @@ /********************************************************************** ** 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> #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> #include <errno.h> #include <qwindowsystem_qws.h> // for qwsServer #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 ) { #if QT_VERSION >= 232 && defined(QWS) connect( qwsServer, SIGNAL( newChannel(const QString&)), this, SLOT( handleNewChannel(const QString&)) ); -#endif +#endif dict.setAutoDelete( TRUE ); } 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; @@ -263,522 +263,522 @@ const QDawg& Global::fixedDawg() 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(QT_NO_COP) +#if !defined(QT_NO_COP) QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); e << message; #endif } /*! \internal */ void Global::applyStyle() { #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(QT_NO_COP) QCopChannel::send( "QPE/System", "shutdown()" ); #endif return 0; } /*! \internal */ QWidget *Global::restart( bool ) { #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(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(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(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(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 - { - bool success = false; + { + bool success = false; int pfd [2]; if ( ::pipe ( pfd ) < 0 ) pfd [0] = pfd [1] = -1; - + pid_t pid = ::fork ( ); - + if ( pid == 0 ) { // child for ( int fd = 3; fd < 100; fd++ ) { if ( fd != pfd [1] ) ::close ( fd ); } ::setpgid ( ::getpid ( ), ::getppid ( )); // Closing of fd[1] indicates that the execvp succeeded! if ( pfd [1] >= 0 ) ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); - + // Try bindir first, so that foo/bar works too ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); ::execvp ( args [0], (char * const *) args ); - + char resultByte = 1; if ( pfd [1] >= 0 ) ::write ( pfd [1], &resultByte, 1 ); - ::_exit ( -1 ); + ::_exit ( -1 ); } else if ( pid > 0 ) { success = true; - - if ( pfd [1] >= 0 ) + + if ( pfd [1] >= 0 ) ::close ( pfd [1] ); if ( pfd [0] >= 0 ) { while ( true ) { char resultByte; int n = ::read ( pfd [0], &resultByte, 1 ); if ( n == 1 ) { success = false; break; } if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) continue; - + break; // success } ::close ( pfd [0] ); } } - if ( success ) + if ( success ) StartingAppList::add( list[0] ); else QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); } #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(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(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 diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index c562f6c..2ef60d5 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp @@ -325,257 +325,257 @@ static void setMic( int t = 0, int percent = -1 ) ::close( fd ); } } break; } } static void setBass( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "BassPercent", 50 ); int fd = 0; int bass = percent; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); ::close( fd ); } } break; } } static void setTreble( int t = 0, int percent = -1 ) { switch ( t ) { case 0: { Config cfg( "qpe" ); cfg.setGroup( "Volume" ); if ( percent < 0 ) percent = cfg.readNumEntry( "TreblePercent", 50 ); int fd = 0; int treble = percent; if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); ::close( fd ); } } break; } } /*! \class QPEApplication qpeapplication.h \brief The QPEApplication class implements various system services that are available to all Qtopia applications. Simply by using QPEApplication instead of QApplication, a standard Qt application becomes a Qtopia application. It automatically follows style changes, quits and raises, and in the case of \link docwidget.html document-oriented\endlink applications, changes the currently displayed document in response to the environment. To create a \link docwidget.html document-oriented\endlink application use showMainDocumentWidget(); to create a non-document-oriented application use showMainWidget(). The keepRunning() function indicates whether the application will continue running after it's processed the last \link qcop.html QCop\endlink message. This can be changed using setKeepRunning(). A variety of signals are emitted when certain events occur, for example, timeChanged(), clockChanged(), weekChanged(), dateFormatChanged() and volumeChanged(). If the application receives a \link qcop.html QCop\endlink message on the application's QPE/Application/\e{appname} channel, the appMessage() signal is emitted. There are also flush() and reload() signals, which are emitted when synching begins and ends respectively - upon these signals, the application should save and reload any data files that are involved in synching. Most of these signals will initially be received and unfiltered through the appMessage() signal. This class also provides a set of useful static functions. The qpeDir() and documentDir() functions return the respective paths. The grabKeyboard() and ungrabKeyboard() functions are used to control whether the application takes control of the device's physical buttons (e.g. application launch keys). The stylus' mode of operation is set with setStylusOperation() and retrieved with stylusOperation(). There are also setInputMethodHint() and inputMethodHint() functions. \ingroup qtopiaemb */ /*! \fn void QPEApplication::clientMoused() \internal */ /*! \fn void QPEApplication::timeChanged(); This signal is emitted when the time changes outside the normal passage of time, i.e. if the time is set backwards or forwards. */ /*! \fn void QPEApplication::clockChanged( bool ampm ); This signal is emitted when the user changes the clock's style. If \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, they want a 24-hour clock. */ /*! \fn void QPEApplication::volumeChanged( bool muted ) This signal is emitted whenever the mute state is changed. If \a muted is TRUE, then sound output has been muted. */ /*! \fn void QPEApplication::weekChanged( bool startOnMonday ) This signal is emitted if the week start day is changed. If \a startOnMonday is TRUE then the first day of the week is Monday; if \a startOnMonday is FALSE then the first day of the week is Sunday. */ /*! - \fn void QPEApplication::dateFormatChanged() + \fn void QPEApplication::dateFormatChanged(DateFormat) This signal is emitted whenever the date format is changed. */ /*! \fn void QPEApplication::flush() ### */ /*! \fn void QPEApplication::reload() */ /*! \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) This signal is emitted when a message is received on this application's QPE/Application/<i>appname</i> \link qcop.html QCop\endlink channel. The slot to which you connect this signal uses \a msg and \a data in the following way: \code void MyWidget::receive( const QCString& msg, const QByteArray& data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } else if ( msg == "otherMessage(QString)" ) { ... } } \endcode \sa qcop.html Note that messages received here may be processed by qpe application and emitted as signals, such as flush() and reload(). */ /*! Constructs a QPEApplication just as you would construct a QApplication, passing \a argc, \a argv, and \a t. For applications, \a t should be the default, GuiClient. Only the Qtopia server passes GuiServer. */ QPEApplication::QPEApplication( int & argc, char **argv, Type t ) : QApplication( argc, argv, t ) { d = new QPEApplicationData; d->loadTextCodecs(); d->loadImageCodecs(); int dw = desktop() ->width(); if ( dw < 200 ) { setFont( QFont( "helvetica", 8 ) ); AppLnk::setSmallIconSize( 10 ); AppLnk::setBigIconSize( 28 ); } else if ( dw > 600 ) { setFont( QFont( "helvetica", 18 ) ); AppLnk::setSmallIconSize( 24 ); AppLnk::setBigIconSize( 48 ); } else if ( dw > 200 ) { setFont( QFont( "helvetica", 10 ) ); AppLnk::setSmallIconSize( 14 ); AppLnk::setBigIconSize( 32 ); } QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); #if defined(Q_WS_QWS) && !defined(QT_NO_COP) QString qcopfn( "/tmp/qcop-msg-" ); qcopfn += QString( argv[ 0 ] ); // append command name QFile f( qcopfn ); if ( f.open( IO_ReadOnly ) ) { flock( f.handle(), LOCK_EX ); } sysChannel = new QCopChannel( "QPE/System", this ); connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); QCString channel = QCString( argv[ 0 ] ); channel.replace( QRegExp( ".*/" ), "" ); d->appName = channel; channel = "QPE/Application/" + channel; pidChannel = new QCopChannel( channel, this ); connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); if ( f.isOpen() ) { d->keep_running = FALSE; QDataStream ds( &f ); QCString channel, message; QByteArray data; while ( !ds.atEnd() ) { ds >> channel >> message >> data; d->enqueueQCop( channel, message, data ); } flock( f.handle(), LOCK_UN ); f.close(); f.remove(); } for ( int a = 0; a < argc; a++ ) { if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { argv[ a ] = argv[ a + 1 ]; a++; d->preloaded = TRUE; argc -= 1; } else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { argv[ a ] = argv[ a + 1 ]; a++; d->preloaded = TRUE; d->forceshow = TRUE; @@ -1643,164 +1643,165 @@ void QPEApplication::removeSenderFromStylusDict() */ bool QPEApplication::keyboardGrabbed() const { return d->kbgrabbed; } /*! Reverses the effect of grabKeyboard(). This is called automatically on program exit. */ void QPEApplication::ungrabKeyboard() { ((QPEApplication *) qApp )-> d-> kbgrabbed = false; } /*! Grabs the physical keyboard keys, e.g. the application's launching keys. Instead of launching applications when these keys are pressed the signals emitted are sent to this application instead. Some games programs take over the launch keys in this way to make interaction easier. \sa ungrabKeyboard() */ void QPEApplication::grabKeyboard() { ((QPEApplication *) qApp )-> d-> kbgrabbed = true; } /*! \reimp */ int QPEApplication::exec() { #ifndef QT_NO_COP d->sendQCopQ(); #endif if ( d->keep_running ) //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) return QApplication::exec(); #ifndef QT_NO_COP { QCopEnvelope e( "QPE/System", "closing(QString)" ); e << d->appName; } #endif processEvents(); return 0; } /*! \internal External request for application to quit. Quits if possible without loosing state. */ void QPEApplication::tryQuit() { if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) return ; // Inside modal loop or konsole. Too hard to save state. #ifndef QT_NO_COP { QCopEnvelope e( "QPE/System", "closing(QString)" ); e << d->appName; } #endif processEvents(); quit(); } /*! \internal User initiated quit. Makes the window 'Go Away'. If preloaded this means hiding the window. If not it means quitting the application. As this is user initiated we don't need to check state. */ void QPEApplication::hideOrQuit() { processEvents(); // If we are a preloaded application we don't actually quit, so emit // a System message indicating we're quasi-closing. if ( d->preloaded && d->qpe_main_widget ) #ifndef QT_NO_COP { QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); e << d->appName; d->qpe_main_widget->hide(); } #endif else quit(); } #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) // The libraries with the skiff package (and possibly others) have // completely useless implementations of builtin new and delete that // use about 50% of your CPU. Here we revert to the simple libc // functions. void* operator new[]( size_t size ) { return malloc( size ); } void* operator new( size_t size ) { return malloc( size ); } void operator delete[]( void* p ) { free( p ); } void operator delete[]( void* p, size_t /*size*/ ) { free( p ); } + void operator delete( void* p ) { free( p ); } void operator delete( void* p, size_t /*size*/ ) { free( p ); } #endif #if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) #include <qwidgetlist.h> #ifdef QWS #include <qgfx_qws.h> extern QRect qt_maxWindowRect; void qt_setMaxWindowRect(const QRect& r ) { qt_maxWindowRect = qt_screen->mapFromDevice( r, qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); // Re-resize any maximized windows QWidgetList* l = QApplication::topLevelWidgets(); if ( l ) { QWidget * w = l->first(); while ( w ) { if ( w->isVisible() && w->isMaximized() ) { w->showMaximized(); } w = l->next(); } delete l; } } #endif #endif diff --git a/library/storage.cpp b/library/storage.cpp index f4c1c02..12f9df9 100644 --- a/library/storage.cpp +++ b/library/storage.cpp @@ -75,187 +75,187 @@ StorageInfo::StorageInfo( QObject *parent ) this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); update(); } const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) { for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { if ( filename.startsWith( (*i)->path() ) ) return (*i); } return 0; } void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) { if ( msg == "mtabChanged()" ) update(); } // cause of the lack of a d pointer we need // to store informations in a config file :( void StorageInfo::update() { //qDebug("StorageInfo::updating"); #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) struct mntent *me; FILE *mntfp = setmntent( "/etc/mtab", "r" ); QStringList curdisks; QStringList curopts; QStringList curfs; bool rebuild = FALSE; int n=0; if ( mntfp ) { while ( (me = getmntent( mntfp )) != 0 ) { QString fs = me->mnt_fsname; if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" || fs.left( 14 ) == "/dev/mmc/part1" || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) { n++; curdisks.append(fs); curopts.append( me->mnt_opts ); //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); curfs.append( me->mnt_dir ); bool found = FALSE; for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { if ( (*i)->disk() == fs ) { found = TRUE; break; } } if ( !found ) rebuild = TRUE; } } endmntent( mntfp ); } if ( rebuild || n != (int)mFileSystems.count() ) { mFileSystems.clear(); QStringList::ConstIterator it=curdisks.begin(); QStringList::ConstIterator fsit=curfs.begin(); QStringList::ConstIterator optsIt=curopts.begin(); for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { QString opts = *optsIt; QString disk = *it; QString humanname; bool removable = FALSE; if ( isCF(disk) ) { humanname = tr("CF Card"); removable = TRUE; } else if ( disk == "/dev/hda1" ) { humanname = tr("Hard Disk"); } else if ( disk.left(9) == "/dev/mmcd" ) { humanname = tr("SD Card"); removable = TRUE; } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { humanname = tr("MMC Card"); removable = TRUE; } else if ( disk.left(7) == "/dev/hd" ) humanname = tr("Hard Disk") + " " + disk; else if ( disk.left(7) == "/dev/sd" ) humanname = tr("SCSI Hard Disk") + " " + disk; else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs humanname = tr("Internal Memory"); else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) humanname = tr("Internal Storage"); else if ( disk.left(14) == "/dev/mtdblock/" ) humanname = tr("Internal Storage") + " " + disk; else if ( disk.left(13) == "/dev/mtdblock" ) humanname = tr("Internal Storage") + " " + disk; else if ( disk.left(9) == "/dev/root" ) humanname = tr("Internal Storage") + " " + disk; else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs humanname = tr("Internal Memory"); FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); mFileSystems.append( fs ); } emit disksChanged(); } else { // just update them for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) i.current()->update(); } #endif } bool deviceTab( const char *device) { QString name = device; bool hasDevice=false; struct mntent *me; FILE *mntfp = setmntent( "/etc/mtab", "r" ); if ( mntfp ) { while ( (me = getmntent( mntfp )) != 0 ) { QString deviceName = me->mnt_fsname; // qDebug(deviceName); if( deviceName.left(name.length()) == name) { hasDevice = true; } } } endmntent( mntfp ); return hasDevice; } /*! - * @fn hasCf() + * @fn static bool StorageInfo::hasCf() * @brief returns whether device has Cf mounted * */ bool StorageInfo::hasCf() { return deviceTab("/dev/hd"); } /*! - * @fn hasSd() + * @fn static bool StorageInfo::hasSd() * @brief returns whether device has SD mounted * */ bool StorageInfo::hasSd() { return deviceTab("/dev/mmcd"); } /*! - * @fn hasMmc() + * @fn static bool StorageInfo::hasMmc() * @brief reutrns whether device has mmc mounted * */ bool StorageInfo::hasMmc() { bool hasMmc=false; if( deviceTab("/dev/mmc/part")) hasMmc=true; if( deviceTab("/dev/mmcd")) hasMmc=true; return hasMmc; } //--------------------------------------------------------------------------- FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) { update(); } void FileSystem::update() { #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) struct statfs fs; if ( !statfs( fspath.latin1(), &fs ) ) { blkSize = fs.f_bsize; totalBlks = fs.f_blocks; availBlks = fs.f_bavail; } else { blkSize = 0; totalBlks = 0; availBlks = 0; } #endif } |