-rw-r--r-- | library/backend/categories.h | 1 | ||||
-rw-r--r-- | library/global.cpp | 49 | ||||
-rw-r--r-- | library/global.h | 6 | ||||
-rw-r--r-- | library/library.pro | 2 | ||||
-rw-r--r-- | library/locationcombo.cpp | 295 | ||||
-rw-r--r-- | library/locationcombo.h | 88 | ||||
-rw-r--r-- | library/qlibrary_unix.cpp | 4 | ||||
-rw-r--r-- | library/timestring.cpp | 255 | ||||
-rw-r--r-- | library/timestring.h | 94 |
9 files changed, 683 insertions, 111 deletions
diff --git a/library/backend/categories.h b/library/backend/categories.h index 91c93e7..6be3bc0 100644 --- a/library/backend/categories.h +++ b/library/backend/categories.h @@ -1,229 +1,230 @@ /********************************************************************** ** 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; +QString categoryFileName(); #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 */ 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; QStringList labels( const QString &app, const QArray<int> &catids ) 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; }; class QPC_EXPORT CheckedListView : public QListView { public: void addCheckableList( const QStringList &options ); void setChecked( const QStringList &checked ); QStringList checked() const; }; #endif diff --git a/library/global.cpp b/library/global.cpp index ec87555..f7a0767 100644 --- a/library/global.cpp +++ b/library/global.cpp @@ -1,812 +1,861 @@ /********************************************************************** ** 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 <qpe/config.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 "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 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 implementation of the writeHWClock() function depends on the AlarmServer implementation. If the AlarmServer is using atd the clock will be synced to hardware. If opie-alarm is used the hardware clock will be synced before suspending the device. opie-alarm is used by iPAQ and Zaurii implementation \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(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 ) ) { // FIXME take it out for now, since it leads to a much to short showing of wait if // some entry is clicked. // Real cause is that ::execute is called twice for document tab. But it would need some larger changes // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there // had the idea that an apploader belongs to the launcher ... //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 #ifdef Q_OS_MACX QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; #else QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; #endif 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; 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 ); } else if ( pid > 0 ) { success = true; 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 ) 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 ) { // 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; } /*! 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(); Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); conf.setGroup("main"); if (!conf.readBoolEntry("check",true)) { continue; } conf.setGroup("subdirs"); if (conf.readBoolEntry("wholemedia",true)) { DocLnkSet ide( path,mimefilter); folder->appendFrom(ide); } else { QStringList subDirs = conf.readListEntry("subdirs",':'); if (subDirs.isEmpty()) { subDirs.append("Documents"); } for (unsigned c = 0; c < subDirs.count();++c) { DocLnkSet ide( path+"/"+subDirs[c], 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() { QString qpeDir = QPEApplication::qpeDir(); QStringList path; QStringList langs = Global::languageList(); for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { QString lang = *it; if ( !lang.isEmpty() ) path += qpeDir + "/help/" + lang + "/html"; } path += qpeDir + "/pics"; path += qpeDir + "/help/html"; /* we even put english into the en dir so try it as fallback as well for opie */ path += qpeDir + "/help/en/html"; path += qpeDir + "/docs"; return path; } +/*! + \internal + Truncate file to size specified + \a f must be an open file + \a size must be a positive value + */ +bool Global::truncateFile(QFile &f, int size){ + if (!f.isOpen()) + return FALSE; + + return ::ftruncate(f.handle(), size) != -1; +} + + + + +// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS) +// extern int qws_display_id; +// #endif + +/*! + /internal + Returns the default system path for storing temporary files. + Note: This does not it ensure that the provided directory exists +*/ +QString Global::tempDir() +{ + QString result; +#ifdef Q_OS_UNIX +#ifdef Q_WS_QWS + result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id)); +#else + result="/tmp/"; +#endif +#else + if (getenv("TEMP")) + result = getenv("TEMP"); + else + result = getenv("TMP"); + + if (result[(int)result.length() - 1] != QDir::separator()) + result.append(QDir::separator()); +#endif + + return result; +} + +//#endif + #include "global.moc" diff --git a/library/global.h b/library/global.h index 1136b12..f32c498 100644 --- a/library/global.h +++ b/library/global.h @@ -1,90 +1,94 @@ /********************************************************************** ** 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 GLOBAL_H #define GLOBAL_H #include <qstringlist.h> #include <qguardedptr.h> class QDawg; class QLabel; class QWidget; class AppLnk; class DocLnkSet; - +class QFile; class Global { public: Global(); // Dictionaries static const QDawg& fixedDawg(); static const QDawg& addedDawg(); static const QDawg& dawg(const QString& name); static void addWords(const QStringList& word); static void addWords(const QString& dictname, const QStringList& word); // static void removeWords(const QStringList& word); -- if someone wants it static void createDocDir(); static void findDocuments(DocLnkSet* folder, const QString &mimefilter=QString::null); static QString applicationFileName(const QString& appname, const QString& filename); struct Command { const char *file; QWidget *(*func)( bool ); bool maximized; bool documentary; }; static void setBuiltinCommands( Command* ); static void execute( const QString &exec, const QString &document=QString::null ); static void setDocument( QWidget* receiver, const QString& document ); static bool terminateBuiltin( const QString& ); static void terminate( const AppLnk* ); static bool isBuiltinCommand( const QString &name ); // system messaging static void applyStyle(); static void statusMessage(const QString&); static QWidget *shutdown( bool = FALSE ); static QWidget *restart( bool = FALSE ); static void hideInputMethod(); static void showInputMethod(); static void writeHWClock(); static QString shellQuote(const QString& s); static QString stringQuote(const QString& s); #ifdef QTOPIA_INTERNAL_LANGLIST static QStringList languageList(); static QStringList helpPath(); #endif +//#ifdef QTOPIA_INTERNAL_FILEOPERATIONS + static bool truncateFile(QFile &f, int size); + static QString tempDir( ); +//#endif private: static void invoke( const QString &exec); static Command* builtin; static QGuardedPtr<QWidget> *running; }; #endif diff --git a/library/library.pro b/library/library.pro index 7143454..4142529 100644 --- a/library/library.pro +++ b/library/library.pro @@ -1,141 +1,143 @@ TEMPLATE = lib #CONFIG += qt warn_on release CONFIG += qt warn_on debug HEADERS = calendar.h \ global.h \ resource.h \ xmlreader.h \ mimetype.h \ menubutton.h \ network.h \ networkinterface.h \ filemanager.h \ fontmanager.h \ qdawg.h \ datebookmonth.h \ fileselector.h \ fileselector_p.h \ imageedit.h \ qcopenvelope_qws.h \ qpedecoration_qws.h \ qpeapplication.h \ qpestyle.h \ qpedialog.h \ lightstyle.h \ config.h \ applnk.h \ sound.h \ tzselect.h \ qmath.h \ datebookdb.h \ alarmserver.h \ process.h \ password.h \ timestring.h \ fontfactoryinterface.h \ fontdatabase.h \ power.h \ storage.h \ qpemessagebox.h \ timeconversion.h \ qpedebug.h \ qpemenubar.h \ qpetoolbar.h \ backend/categories.h \ stringutil.h \ backend/palmtoprecord.h \ backend/task.h \ backend/event.h \ backend/contact.h\ categorymenu.h \ categoryedit_p.h \ categoryselect.h \ categorywidget.h \ ir.h \ backend/vobject_p.h \ findwidget_p.h \ finddialog.h \ lnkproperties.h \ windowdecorationinterface.h \ textcodecinterface.h \ imagecodecinterface.h \ + locationcombo.h \ qpeglobal.h SOURCES = calendar.cpp \ global.cpp \ xmlreader.cpp \ mimetype.cpp \ menubutton.cpp \ network.cpp \ networkinterface.cpp \ filemanager.cpp \ fontmanager.cpp \ qdawg.cpp \ datebookmonth.cpp \ fileselector.cpp \ imageedit.cpp \ resource.cpp \ qpedecoration_qws.cpp \ qcopenvelope_qws.cpp \ qpeapplication.cpp \ qpestyle.cpp \ qpedialog.cpp \ lightstyle.cpp \ config.cpp \ applnk.cpp \ sound.cpp \ tzselect.cpp \ qmath.c \ datebookdb.cpp \ alarmserver.cpp \ password.cpp \ process.cpp \ process_unix.cpp \ timestring.cpp \ fontdatabase.cpp \ power.cpp \ storage.cpp \ qpemessagebox.cpp \ backend/timeconversion.cpp \ qpedebug.cpp \ qpemenubar.cpp \ qpetoolbar.cpp \ backend/categories.cpp \ backend/stringutil.cpp \ backend/palmtoprecord.cpp \ backend/task.cpp \ backend/event.cpp \ backend/contact.cpp \ categorymenu.cpp \ categoryedit_p.cpp \ categoryselect.cpp \ categorywidget.cpp \ ir.cpp \ backend/vcc_yacc.cpp \ backend/vobject.cpp \ findwidget_p.cpp \ finddialog.cpp \ lnkproperties.cpp \ + locationcombo.cpp \ widget_showing.cpp # Qt 3 compatibility HEADERS += quuid.h qcom.h qlibrary.h qlibrary_p.h SOURCES += quuid.cpp qlibrary.cpp qlibrary_unix.cpp DEFINES += OPIE_INTERNAL_LIBRARY_BUILD INCLUDEPATH += $(OPIEDIR)/include backend LIBS += -ldl -lcrypt -lm INTERFACES = passwordbase_p.ui categoryeditbase_p.ui findwidgetbase_p.ui lnkpropertiesbase_p.ui TARGET = qpe DESTDIR = $(OPIEDIR)/lib$(PROJMAK) VERSION = 1.5.0.1 include( $(OPIEDIR)/include.pro ) contains( CONFIG, LIBQPE_WITHROHFEEDBACK ){ DEFINES += OPIE_WITHROHFEEDBACK SOURCES += backend/rohfeedback.cpp HEADERS += backend/rohfeedback.h } diff --git a/library/locationcombo.cpp b/library/locationcombo.cpp new file mode 100644 index 0000000..31429f5 --- a/dev/null +++ b/library/locationcombo.cpp @@ -0,0 +1,295 @@ +/********************************************************************** +** Copyright (C) 2000-2006 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 2 of the License, or (at your +** option) any later version. +** +** A copy of the GNU GPL license version 2 is included in this package as +** LICENSE.GPL. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +** See the GNU General Public License for more details. +** +** In addition, as a special exception Trolltech gives permission to link +** the code of this program with Qtopia applications copyrighted, developed +** and distributed by Trolltech under the terms of the Qtopia Personal Use +** License Agreement. You must comply with the GNU General Public License +** in all respects for all of the code used other than the applications +** licensed under the Qtopia Personal Use License Agreement. If you modify +** this file, you may extend this exception to your version of the file, +** but you are not obligated to do so. If you do not wish to do so, delete +** this exception statement from your version. +** +** 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 "locationcombo.h" + +#include <qpe/ir.h> +#include <qpe/applnk.h> +#include <qpe/global.h> +#include <qpe/categorywidget.h> +#include <qpe/categoryselect.h> +#ifdef QWS +#include <qpe/qcopenvelope_qws.h> +#endif +#include <qpe/filemanager.h> +#include <qpe/config.h> +#include <qpe/storage.h> +#include <qpe/global.h> +#include <qtopia/qpemessagebox.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 <qdir.h> +#include <qfileinfo.h> +#include <qmessagebox.h> +#include <qsize.h> +#include <qcombobox.h> +#include <qregexp.h> + +#include <qradiobutton.h> +#include <qlayout.h> + +#include <stdlib.h> + +/*! + \class LocationCombo locationcombo.h + \brief The LocationCombo class displays a list of available storage + locations. + + First availability: Qtopia 1.6 + + \ingroup qtopiaemb + \sa DocPropertiesDialog + */ + + +class LocationComboPrivate +{ +public: + LocationComboPrivate() : homeLocation(-1), fileSize(0), listEmpty(TRUE) {} + QString originalPath; + int homeLocation; + int fileSize; + bool listEmpty; +}; + +/*! + Constructs a LocationCombo with parent \a parent and name \a name. + */ +LocationCombo::LocationCombo( QWidget *parent, const char *name ) + : QComboBox( FALSE, parent, name ) +{ + storage = new StorageInfo; + d = new LocationComboPrivate; + setLocation( 0 ); + connect( this, SIGNAL(activated(int)), this, SIGNAL(newPath()) ); + connect( storage, SIGNAL(disksChanged()), this, SLOT(updatePaths()) ); +} + +/*! + Constructs a LocationCombo with parent \a parent and name \a name. + \a lnk is pointer to an existing AppLnk. + */ +LocationCombo::LocationCombo( const AppLnk * lnk, QWidget *parent, const char *name ) + : QComboBox( FALSE, parent, name ) +{ + storage = new StorageInfo; + d = new LocationComboPrivate; + setLocation(lnk); + connect( this, SIGNAL(activated(int)), this, SIGNAL(newPath()) ); + connect( storage, SIGNAL(disksChanged()), this, SLOT(updatePaths()) ); +} + +/*! + Destroys the widget. + */ +LocationCombo::~LocationCombo() +{ + delete storage; + delete d; +} + +/*! + Sets the display of the LocationCombo to the location associated with the + AppLnk \a lnk. + */ +void LocationCombo::setLocation( const AppLnk * lnk ) +{ + // NB: setLocation(const QString) assumes only lnk->file() is used. + + if ( lnk ) { + QFileInfo fi( lnk->file() ); + d->fileSize = fi.size(); + const FileSystem *fs = storage->fileSystemOf( lnk->file() ); + d->originalPath = fs ? fs->path() : QString::null; + } else { + d->fileSize = 0; + d->originalPath = QString::null; + } + + setupCombo(); + + int currentLocation = -1; + if ( lnk ) { + int n = locations.count(); + for ( int i = 0; i < n; i++ ) { + if ( lnk->file().contains( locations[i] ) ) + currentLocation = i; + } + } + if ( currentLocation == -1 ) + currentLocation = 0; //default to the first one + + setCurrentItem( currentLocation ); +} + +/*! + \internal +*/ +void LocationCombo::setupCombo() +{ + clear(); + locations.clear(); + + const QList<FileSystem> &fs = storage->fileSystems(); + QListIterator<FileSystem> it ( fs ); + QString s; + QString homeDir = QDir::homeDirPath(); + QString homeFs; + QString homeFsPath; + int index = 0; + for ( ; it.current(); ++it ) { + // we add 10k to the file size so we are sure we can also save the desktop file + if ( !d->fileSize || (*it)->path() == d->originalPath || + (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() + > (ulong)d->fileSize + 10000 ) + { + if ( (*it)->isRemovable() ) { + insertItem( (*it)->name(), index ); + locations.append( (*it)->path() ); + index++; + } else if ( homeDir.contains( (*it)->path() ) && + (*it)->path().length() > homeFsPath.length() ) { + homeFs = (*it)->name(); + homeFsPath = (*it)->path(); + } + } + } + + // $HOME is *somewhere*, but not shown in Storage::fileSystems(), + // eg. because it's mounted in some unexpected way. + if ( homeFsPath.isEmpty() ) { + homeFs = StorageInfo::tr("Internal Storage"); + homeFsPath = homeDir; + } + + if ( !homeFsPath.isEmpty() ) { + d->homeLocation = 0; + insertItem( homeFs, d->homeLocation ); + locations.prepend( homeDir ); + } else { + d->homeLocation = -1; + } + + d->listEmpty = locations.count() == 0; + if ( d->listEmpty ) { + insertItem( tr("No FileSystems Available!"), 0 ); + locations.append( "" ); + } +} + +/*! + \internal + */ +void LocationCombo::updatePaths() +{ + QString oldPath = locations[currentItem()]; + + setupCombo(); + + int currentLocation = 0; + int n = locations.count(); + for ( int i = 0; i < n; i++ ) { + if ( oldPath == locations[i] ) { + currentLocation = i; + } + } + setCurrentItem( currentLocation ); + if ( locations[currentItem()] != oldPath ) + emit newPath(); +} + +/*! + Returns TRUE to indicate that the user has changed the location displayed + by the LocationCombo. Most useful when the LocationCombo is part of a + dialog; when the dialog is accept()ed, LocationCombo::isChanged() can be + examined to check for a change of location. + */ +bool LocationCombo::isChanged() const +{ + if ( const FileSystem *fs = storage->fileSystemOf(locations[currentItem()]) ) + return fs->path() != d->originalPath; + + return TRUE; +} + +/*! + Returns the default (home) location for the file associated with this + LocationCombo. + */ +QString LocationCombo::installationPath() const +{ + return currentItem() == d->homeLocation ? + QString("/") : locations[ currentItem() ]+"/"; +} + +/*! + Returns the document path associated with this LocationCombo. This + will be "\<path\>/Documents". + */ +QString LocationCombo::documentPath() const +{ + return locations[ currentItem() ]+"/Documents/"; +} + +/*! + Returns a pointer to FileSystem object, associated with the current + selection of the LocationCombo. + */ +const FileSystem *LocationCombo::fileSystem() const +{ + if ( d->listEmpty ) + return 0; + return storage->fileSystemOf( locations[ currentItem() ] ); +} + +/*! + \fn LocationCombo::newPath() + Emitted when the LocationCombo changes to a new location. + */ + + +#if 0 +void LocationCombo::apply() +{ +} +#endif + diff --git a/library/locationcombo.h b/library/locationcombo.h new file mode 100644 index 0000000..fab3dfc --- a/dev/null +++ b/library/locationcombo.h @@ -0,0 +1,88 @@ +/********************************************************************** +** Copyright (C) 2000-2006 Trolltech AS. All rights reserved. +** +** This file is part of the Qtopia Environment. +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 2 of the License, or (at your +** option) any later version. +** +** A copy of the GNU GPL license version 2 is included in this package as +** LICENSE.GPL. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +** See the GNU General Public License for more details. +** +** In addition, as a special exception Trolltech gives permission to link +** the code of this program with Qtopia applications copyrighted, developed +** and distributed by Trolltech under the terms of the Qtopia Personal Use +** License Agreement. You must comply with the GNU General Public License +** in all respects for all of the code used other than the applications +** licensed under the Qtopia Personal Use License Agreement. If you modify +** this file, you may extend this exception to your version of the file, +** but you are not obligated to do so. If you do not wish to do so, delete +** this exception statement from your version. +** +** 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 LOCATIONCOMBO_H +#define LOCATIONCOMBO_H + +#include <qpe/qpeglobal.h> + +#ifdef Q_WS_QWS + +#include <qstringlist.h> +#include <qcombobox.h> + +class AppLnk; +class QListViewItem; +class DocLnk; +class FileSystem; +class StorageInfo; + + +class LocationComboPrivate; + +class LocationCombo : public QComboBox +{ + Q_OBJECT +public: + LocationCombo( QWidget *parent, const char *name=0 ); + LocationCombo( const AppLnk * lnk, QWidget *parent, const char *name=0 ); + + ~LocationCombo(); + + void setLocation( const QString& path ); // qtopia 2 + void setLocation( const AppLnk * ); + + QString installationPath() const; + QString documentPath() const; + const FileSystem *fileSystem() const; + + bool isChanged() const; + +signals: + void newPath(); + +private slots: + void updatePaths(); + +private: + void setupCombo(); + QStringList locations; + StorageInfo *storage; + LocationComboPrivate *d; +}; + + +#endif // QWS +#endif // LNKPROPERTIES_H diff --git a/library/qlibrary_unix.cpp b/library/qlibrary_unix.cpp index fee73c2..f4d60cb 100644 --- a/library/qlibrary_unix.cpp +++ b/library/qlibrary_unix.cpp @@ -1,243 +1,243 @@ /********************************************************************** ** 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 "qlibrary_p.h" #ifndef QT_NO_COMPONENT /* The platform dependent implementations of - loadLibrary - freeLibrary - resolveSymbol It's not too hard to guess what the functions do. */ #if defined(Q_OS_HPUX) // for HP-UX < 11.x and 32 bit #include <dl.h> bool QLibraryPrivate::loadLibrary() { if ( pHnd ) return TRUE; QString filename = library->library(); pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) if ( !pHnd ) qDebug( "Failed to load library %s!", filename.latin1() ); #endif return pHnd != 0; } bool QLibraryPrivate::freeLibrary() { if ( !pHnd ) return TRUE; if ( !shl_unload( (shl_t)pHnd ) ) { pHnd = 0; return TRUE; } return FALSE; } void* QLibraryPrivate::resolveSymbol( const char* symbol ) { if ( !pHnd ) return 0; void* address = 0; if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) { #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) qDebug( "Couldn't resolve symbol \"%s\"", symbol ); #endif return 0; } return address; } #elif defined(_NULL_LIB_) bool QLibraryPrivate::loadLibrary() { //qDebug("QLibraryPrivate::loadLibrary\n"); return FALSE; } bool QLibraryPrivate::freeLibrary() { //qDebug("QLibraryPrivate::freeLibrary\n"); return FALSE; } void* QLibraryPrivate::resolveSymbol( const char* symbol ) { //qDebug("QLibraryPrivate::resolveSymbol\n"); return FALSE; } #elif defined(Q_OS_MACX) #define ENUM_DYLD_BOOL enum DYLD_BOOL { DYLD_FALSE, DYLD_TRUE }; #include <mach-o/dyld.h> typedef struct { NSObjectFileImage img; NSModule mod; } DyldLibDesc; bool QLibraryPrivate::loadLibrary() { // qDebug("QLibraryPrivate::loadLibrary\n"); // return FALSE; if ( pHnd ) return TRUE; QString filename = library->library(); NSObjectFileImage img = 0; NSModule mod = 0; NSObjectFileImageReturnCode ret = NSCreateObjectFileImageFromFile( filename.latin1() , &img ); if ( ret != NSObjectFileImageSuccess ) { qWarning( "Error in NSCreateObjectFileImageFromFile(): %d; Filename: %s", ret, filename.latin1() ); if (ret == NSObjectFileImageAccess) { qWarning ("(NSObjectFileImageAccess)" ); } } else { mod = NSLinkModule(img, filename.latin1(), NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_PRIVATE | NSLINKMODULE_OPTION_RETURN_ON_ERROR); if (mod == 0) { qWarning( "Error in NSLinkModule()" ); NSDestroyObjectFileImage(img); } } DyldLibDesc* desc = 0; if (img != 0 && mod != 0) { desc = new DyldLibDesc; desc->img = img; desc->mod = mod; } pHnd = desc; return pHnd != 0; } bool QLibraryPrivate::freeLibrary() { //qDebug("QLibraryPrivate::freeLibrary\n"); //return FALSE; if ( !pHnd ) return TRUE; DyldLibDesc* desc = (DyldLibDesc*) pHnd; NSModule mod = desc->mod; NSObjectFileImage img = desc->img; bool success = NSUnLinkModule(mod, NSUNLINKMODULE_OPTION_NONE); if ( success ) { NSDestroyObjectFileImage(img); delete desc; pHnd = 0; } #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) else { qWarning( "Error in NSUnLinkModule()" ); } #endif return pHnd == 0; } void* QLibraryPrivate::resolveSymbol( const char* symbol ) { //qDebug("QLibraryPrivate::resolveSymbol\n"); //return FALSE; if ( !pHnd ) return 0; DyldLibDesc* desc = (DyldLibDesc*) pHnd; NSSymbol sym = NSLookupSymbolInModule(desc->mod, symbol); void* address = 0; if (sym != 0) { address = NSAddressOfSymbol(sym); } #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) if ( address == 0 ) qWarning( "Cannot find symbol: %s", symbol ); #endif return address; } #else // Something else, assuming POSIX #include <dlfcn.h> bool QLibraryPrivate::loadLibrary() { if ( pHnd ) return TRUE; QString filename = library->library(); - pHnd = dlopen( filename.latin1() , RTLD_LAZY ); + pHnd = ::dlopen( filename.latin1() , RTLD_LAZY ); // #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) if ( !pHnd ) qWarning( "%s", dlerror() ); // #endif return pHnd != 0; } bool QLibraryPrivate::freeLibrary() { if ( !pHnd ) return TRUE; - int ec = dlclose( pHnd ); + int ec = ::dlclose( pHnd ); if ( !ec ) pHnd = 0; #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) else { const char* error = dlerror(); if ( error ) qWarning( "%s", error ); } #endif return pHnd == 0; } void* QLibraryPrivate::resolveSymbol( const char* f ) { if ( !pHnd ) return 0; void* address = dlsym( pHnd, f ); #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) const char* error = dlerror(); if ( error ) qWarning( "%s", error ); #endif return address; } #endif // POSIX #endif // QT_NO_COMPONENT diff --git a/library/timestring.cpp b/library/timestring.cpp index 91c29ae..afd162d 100644 --- a/library/timestring.cpp +++ b/library/timestring.cpp @@ -1,365 +1,466 @@ /********************************************************************** -** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2006 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 program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 2 of the License, or (at your +** option) any later version. ** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** A copy of the GNU GPL license version 2 is included in this package as +** LICENSE.GPL. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +** See the GNU General Public License for more details. +** +** In addition, as a special exception Trolltech gives permission to link +** the code of this program with Qtopia applications copyrighted, developed +** and distributed by Trolltech under the terms of the Qtopia Personal Use +** License Agreement. You must comply with the GNU General Public License +** in all respects for all of the code used other than the applications +** licensed under the Qtopia Personal Use License Agreement. If you modify +** this file, you may extend this exception to your version of the file, +** but you are not obligated to do so. If you do not wish to do so, delete +** this exception statement from your version. ** ** 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 "timestring.h" #include <qobject.h> -#include <qpe/qpeapplication.h> //for qApp +#include <qdatetime.h> +#include <qapplication.h> #include "config.h" +#include <time.h> + -class TimeStringFormatKeeper : public QObject +class TimeStringFormat : public QObject { Q_OBJECT public: static DateFormat currentFormat() { if ( !self ) - self = new TimeStringFormatKeeper; + self = new TimeStringFormat; return self->format; } private slots: void formatChanged( DateFormat f ) { format = f; } private: - static TimeStringFormatKeeper *self; + static TimeStringFormat *self; DateFormat format; - TimeStringFormatKeeper() + TimeStringFormat() : QObject( qApp ) { Config config("qpe"); config.setGroup( "Date" ); - format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), - (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), - (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); + format = ::DateFormat(QChar(config.readEntry("Separator", "/")[0]), + (::DateFormat::Order)config.readNumEntry("ShortOrder", ::DateFormat::DayMonthYear), + (::DateFormat::Order)config.readNumEntry("LongOrder", ::DateFormat::DayMonthYear)); connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ), this, SLOT( formatChanged(DateFormat) ) ); } }; -TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0; +TimeStringFormat *TimeStringFormat::self = 0; QString DateFormat::toNumberString() const { QString buf = ""; // for each part of the order for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_shortOrder >> (i * 3)) & 0x0007) { case 0x0001: - buf += QObject::tr( "D" , "Shortcut for Day"); + buf += TimeStringFormat::tr( "D", "first letter of the word 'Day'" ); break; case 0x0002: - buf += QObject::tr( "M", "Shortcur for Month" ); + buf += TimeStringFormat::tr( "M" , "first letter of the word 'Month'" ); break; case 0x0004: - buf += QObject::tr( "Y" ); + buf += TimeStringFormat::tr( "Y" , "first letter of the word 'Year'" ); break; } if (i < 2) buf += _shortSeparator; } return buf; } QString DateFormat::toWordString() const { QString buf = ""; // for each part of the order for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_longOrder >> (i * 3)) & 0x0007) { case 0x0001: - buf += QObject::tr( "day" ); + buf += TimeStringFormat::tr( "day", "in month" ); if (i < 2) { if ((_shortOrder << ((i+1) * 3)) & 0x0007) buf += ", "; else buf += " "; } break; case 0x0002: - buf += QObject::tr( "month" ); + buf += TimeStringFormat::tr( "month" ); if (i < 2) buf += " "; break; case 0x0004: - buf += QObject::tr( "year" ); + buf += TimeStringFormat::tr( "year" ); if (i < 2) buf += ", "; break; } } return buf; } QString DateFormat::numberDate(const QDate &d, int v) const { QString buf = ""; int pad = 2; // for each part of the order for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. switch((_shortOrder >> (i * 3)) & 0x0007) { case 0x0001: if (pad==2) buf += QString().sprintf("%02d",d.day()); else buf += QString().sprintf("%d",d.day()); break; case 0x0002: if (i==0) { // no padding with only MM/DD/YY format pad=0; } if (pad==2) buf += QString().sprintf("%02d",d.month()); else buf += QString().sprintf("%d",d.month()); break; case 0x0004: { int year = d.year(); if (!(v & longNumber)) year = year % 100; buf += QString().sprintf("%02d",year); } break; } if (i < 2) buf += _shortSeparator; } return buf; } +static const char* unTranslatedFullMonthNames[] = { + QT_TRANSLATE_NOOP( "QDate", "January" ), + QT_TRANSLATE_NOOP( "QDate", "February" ), + QT_TRANSLATE_NOOP( "QDate", "March" ), + QT_TRANSLATE_NOOP( "QDate", "April" ), + QT_TRANSLATE_NOOP( "QDate", "May" ), + QT_TRANSLATE_NOOP( "QDate", "June" ), + QT_TRANSLATE_NOOP( "QDate", "July" ), + QT_TRANSLATE_NOOP( "QDate", "August" ), + QT_TRANSLATE_NOOP( "QDate", "September" ), + QT_TRANSLATE_NOOP( "QDate", "October" ), + QT_TRANSLATE_NOOP( "QDate", "November" ), + QT_TRANSLATE_NOOP( "QDate", "December" ) +}; + +static const char* unTranslatedFullDayNames[] = { + QT_TRANSLATE_NOOP( "QDate", "Monday" ), + QT_TRANSLATE_NOOP( "QDate", "Tuesday" ), + QT_TRANSLATE_NOOP( "QDate", "Wednesday" ), + QT_TRANSLATE_NOOP( "QDate", "Thursday" ), + QT_TRANSLATE_NOOP( "QDate", "Friday" ), + QT_TRANSLATE_NOOP( "QDate", "Saturday" ), + QT_TRANSLATE_NOOP( "QDate", "Sunday" ) +}; + +#ifdef QTOPIA_DESKTOP +//translations in qt.qm +static const char* unTranslatedMediumDayNames[] = { + "Mon" , "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" +}; + +static const char* unTranslatedMediumMonthNames[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; +#endif + +static QString dayname(const QDate& d, bool lng) +{ + if (lng && qApp) + return qApp->translate("QDate", unTranslatedFullDayNames[d.dayOfWeek()-1]); + else { +#ifdef QTOPIA_DESKTOP + if (qApp) + return qApp->translate("QDate", unTranslatedMediumDayNames[ d.dayOfWeek()-1]); +#endif + return d.dayName(d.dayOfWeek()); + } +} + QString DateFormat::wordDate(const QDate &d, int v) const { - QString buf = ""; // for each part of the order - if (v & showWeekDay) { - QString weekDay = d.dayName(d.dayOfWeek()); - if (!(v & longWord)) { - weekDay = weekDay.left(3); - } - buf += weekDay; - if ((_longOrder & 0x0007) == 0x0002) - buf += ' '; - else - buf += ", "; - } + QString weekDay; + if (v & showWeekDay) + weekDay = ::dayname(d,(v & longWord)); + QString date=""; + QString sep=""; for (int i = 0; i < 3; i++) { // switch on the relavent 3 bits. - switch((_longOrder >> (i * 3)) & 0x0007) { - case 0x0001: - if (i==1) { - buf += QString().sprintf("%02d, ",d.day()); - } else { - buf += QString().sprintf("%2d",d.day()); - if (separator()=='.') // 2002/1/11 - buf += ". "; - else - buf += " "; - } + int field = (_longOrder >> (i * 3)) & 0x0007; + if ( field && !date.isEmpty() ) + date += sep; + switch (field) { + case 0x0001: // Day + { + QString daysuffix = TimeStringFormat::tr("@day", "day suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@day' " ); + if (i==1) { + date += QString().sprintf("%02d",d.day()); + if (daysuffix != "@day") + date+=daysuffix; + sep = TimeStringFormat::tr(",","day-date separator") + " "; + } else { + date += QString().sprintf("%2d",d.day()); + if (daysuffix == "@day") { + if (separator()=='.') // 2002/1/11 + sep = ". "; + else + sep = " "; + } else { + date += daysuffix+" "; + sep = " "; + } + } + } break; - case 0x0002: + case 0x0002: // Month { - QString monthName = d.monthName(d.month()); - if (!(v & longWord)) { - monthName = monthName.left(3); - } - buf += monthName; + QString monthName; + + if (v & longWord) + monthName = qApp->translate("QDate", unTranslatedFullMonthNames[d.month()-1] ); + else { +#ifdef QTOPIA_DESKTOP + monthName = qApp->translate("QDate", unTranslatedMediumMonthNames[d.month()-1] ); +#else + monthName = d.monthName( d.month() ); +#endif + } + date += monthName; } - if (i < 2) - buf += " "; + sep = " ";//TimeStringFormat::tr(" ","month-date separator"); break; - case 0x0004: + case 0x0004: // Year { int year = d.year(); if (!(v & longNumber)) year = year % 100; if (year < 10) - buf += "0"; + date += "0"; + + date += QString::number(year); + QString yearsuffix = TimeStringFormat::tr("@year", "year suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@year' " ); + if (yearsuffix != "@year") + date += yearsuffix; - buf += QString::number(year); } - if (i < 2) - buf += ", "; + sep = TimeStringFormat::tr(",","year-date seperator") + " "; break; } } - return buf; + + QString r = ""; + if ( weekDay.isEmpty() ) + r = date; + else if ((_longOrder & 0x0007) == 0x0002) + r = TimeStringFormat::tr("%1 %2","1=Monday 2=January 12").arg(weekDay).arg(date); + else if ( _longOrder ) + r = TimeStringFormat::tr("%1, %2","1=Monday 2=12 January").arg(weekDay).arg(date); + else + r = weekDay; + return r; } #ifndef QT_NO_DATASTREAM void DateFormat::save(QDataStream &d) const { d << _shortSeparator.unicode(); uint v= _shortOrder; d << v; v = _longOrder; d << v; } void DateFormat::load(QDataStream &d) { ushort value; d >> value; _shortSeparator = QChar(value); uint v = 0; d >> v; _shortOrder = (Order)v; v = 0; d >> v; _longOrder = (Order)v; } QDataStream &operator<<(QDataStream &s, const DateFormat&df) { df.save(s); return s; } QDataStream &operator>>(QDataStream &s, DateFormat&df) { df.load(s); return s; } #endif QString TimeString::shortDate( const QDate &d, DateFormat dtf ) { return dtf.wordDate(d); } QString TimeString::dateString( const QDate &d, DateFormat dtf ) { - return QObject::tr( dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord) ); + return dtf.wordDate(d, DateFormat::longNumber); } QString TimeString::longDateString( const QDate &d, DateFormat dtf ) { - return QObject::tr( dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber - | DateFormat::longWord) ); + return dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber + | DateFormat::longWord); } DateFormat TimeString::currentDateFormat() { - return TimeStringFormatKeeper::currentFormat(); + return TimeStringFormat::currentFormat(); } QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf ) { const QDate& d = dt.date(); const QTime& t = dt.time(); // based on QDateTime::toString() QString buf = timeString(t,ampm,seconds); buf += " "; buf += longDateString( d, dtf ); return buf; } QString TimeString::timeString( const QTime &t, bool ampm, bool seconds ) { if ( !ampm ) { if ( seconds ) return t.toString(); QString r = QString::number(t.hour()); if ( t.hour() < 10 ) r.prepend( "0" ); r.append( ":" ); if ( t.minute() < 10 ) r.append( "0" ); r.append(QString::number(t.minute())); return r; } // ### else the hard case that should disappear in Qt 3.0 QString argString = seconds ? "%4:%5:%6 %7" : "%4:%5 %7"; int hour = t.hour(); QString strMin = QString::number( t.minute() ); QString strSec = QString::number( t.second() ); if ( hour > 12 ) argString = argString.arg( hour - 12, 2 ); else { if ( hour == 0 ) argString = argString.arg( 12 ); else argString = argString.arg( hour, 2 ); } if ( t.minute() < 10 ) strMin.prepend( "0" ); if ( t.second() < 10 ) strSec.prepend( "0" ); argString = argString.arg( strMin ); if ( seconds ) argString = argString.arg( strSec ); if ( hour >= 12 ) - argString = argString.arg( QObject::tr("PM") ); + argString = argString.arg( TimeStringFormat::tr("PM") ); else - argString = argString.arg( QObject::tr("AM") ); + argString = argString.arg( TimeStringFormat::tr("AM") ); return argString; } QString TimeString::shortTime( bool ampm, bool seconds ) { - static const char* const day[] = { - QT_TRANSLATE_NOOP( "QObject", "Mon" ), - QT_TRANSLATE_NOOP( "QObject", "Tue" ), - QT_TRANSLATE_NOOP( "QObject", "Wed" ), - QT_TRANSLATE_NOOP( "QObject", "Thu" ), - QT_TRANSLATE_NOOP( "QObject", "Fri" ), - QT_TRANSLATE_NOOP( "QObject", "Sat" ), - QT_TRANSLATE_NOOP( "QObject", "Sun" ) - }; // just create a shorter time String QDateTime dtTmp = QDateTime::currentDateTime(); - QString strTime; - strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + - timeString( dtTmp.time(), ampm, seconds ); + QString strTime = TimeStringFormat::tr( "%1 %2", "1=Monday 2=12:45" ) + .arg(::dayname(dtTmp.date(),FALSE)) + .arg(timeString( dtTmp.time(), ampm, seconds )); return strTime; } QString TimeString::dateString( const QDateTime &t, bool ampm ) { return dateString(t,ampm,FALSE); } QString TimeString::timeString( const QTime &t, bool ampm) { return timeString(t,ampm,FALSE); } QString TimeString::shortTime( bool ampm ) { return shortTime(ampm,FALSE); } QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) { return dtf.numberDate(d); } QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) { return dtf.numberDate(d,DateFormat::longNumber); } +/*! + Returns date/time \a dt as a string, + showing year, month, date, hours, minutes, and seconds. + \a len determines the length of the resulting string. + + The format, including order depends on the user's settings. + + First availability: Qtopia 1.6 +*/ +//QString TimeString::localYMDHMS( const QDateTime &dt, Length len ) +//{ +// const QDate& d = dt.date(); +// const QTime& t = dt.time(); +// return LocalTimeFormat::tr("%1 %2","date,time").arg(localYMD(d,len)).arg(localHMS(t)); +//} + #include "timestring.moc" diff --git a/library/timestring.h b/library/timestring.h index 875c8bf..b8d1aea 100644 --- a/library/timestring.h +++ b/library/timestring.h @@ -1,150 +1,182 @@ /********************************************************************** -** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2006 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 2 of the License, or (at your +** option) any later version. +** +** A copy of the GNU GPL license version 2 is included in this package as +** LICENSE.GPL. ** -** 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. +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +** See the GNU General Public License for more details. ** +** In addition, as a special exception Trolltech gives permission to link +** the code of this program with Qtopia applications copyrighted, developed +** and distributed by Trolltech under the terms of the Qtopia Personal Use +** License Agreement. You must comply with the GNU General Public License +** in all respects for all of the code used other than the applications +** licensed under the Qtopia Personal Use License Agreement. If you modify +** this file, you may extend this exception to your version of the file, +** but you are not obligated to do so. If you do not wish to do so, delete +** this exception statement from your version. +** ** 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 _TIMESTRING_H_ #define _TIMESTRING_H_ #include <qdatetime.h> #include <qstring.h> +#include <qarray.h> #if (QT_VERSION-0 >= 0x030000) #define DateFormat QPEDateFormat #endif +#include <qtopia/qpeglobal.h> + +class QObject; + // return a string with the time based on whether or not you want // you want it in 12 hour form. if ampm is true, then return // it in 12 hour (am/pm) form otherwise return it in 24 hour form // in theory Qt 3,0 handles this better (hopefully obsoleteing this) -class DateFormat +class DateFormat { public: - // date format type 001,010,100 = day month year + // date format type 1,2,4 = day,month,year enum Order { - DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3) - MonthDayYear = 0x010A, - YearMonthDay = 0x0054 + DayMonthYear = 0421, // right-to-left + MonthDayYear = 0412, + YearMonthDay = 0124 }; DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so), _longOrder(so), _shortSeparator(s) { } DateFormat(QChar s, Order so, Order lo) : _shortOrder(so), _longOrder(lo), _shortSeparator(s) { } DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder), _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { } bool operator==(const DateFormat &o) { if (o._shortOrder == _shortOrder && o._longOrder == _longOrder && o._shortSeparator == _shortSeparator) return TRUE; return FALSE; } // verbosity specifiers enum Verbosity { shortNumber = 0x01, // default longNumber = 0x02, padNumber = 0x04, shortWord = 0x08, // default longWord = 0x10, showWeekDay = 0x20 }; QString toNumberString() const; // the M/D/Y string. QString toWordString() const; // the Month day, year string. QString numberDate(const QDate &d, int v = 0) const; QString wordDate(const QDate &d, int v = 0) const; #ifndef QT_NO_DATASTREAM void load(QDataStream&); void save(QDataStream&) const; #endif QChar separator() const { return _shortSeparator; }; Order shortOrder() const { return _shortOrder; }; Order longOrder() const { return _longOrder; }; private: Order _shortOrder; Order _longOrder; QChar _shortSeparator; }; #ifndef QT_NO_DATASTREAM QDataStream &operator<<(QDataStream &s, const DateFormat&df); QDataStream &operator>>(QDataStream &s, DateFormat&df); #endif class TimeString { public: - //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, + //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, //YearMonthDay = ISO8601 }; -/** - * @name Convience functions which use currentDateFormat - */ -//@{ - static QString shortDate( const QDate &d ) + +//private: + static QString shortDate( const QDate &d ) { return shortDate( d, currentDateFormat() ); } static QString dateString( const QDate &d ) { return dateString( d, currentDateFormat() ); } static QString longDateString( const QDate &d ) { return longDateString( d, currentDateFormat() ); } -//@} static QString dateString( const QDateTime &dt, bool ampm, bool seconds ) { return dateString( dt, ampm, seconds, currentDateFormat() ); } +public: + enum Length { Short, Medium, Long }; + static QString localH( int hour ); + static QString localHM( const QTime & ); + static QString localHM( const QTime &, Length ); // qtopia 2.1.0 + static QString localHMS( const QTime & ); + static QString localHMDayOfWeek( const QDateTime &t ); + static QString localHMSDayOfWeek( const QDateTime &t ); + static QString localMD( const QDate &, Length=Medium ); + static QString localYMD( const QDate &, Length=Medium ); + static QString localYMDHMS( const QDateTime &, Length=Medium ); + static QString localDayOfWeek( const QDate&, Length=Medium ); + static QString localDayOfWeek( int day1to7, Length=Medium ); + + static QString hourString( int hour, bool ampm ); + static bool currentAMPM(); + static DateFormat currentDateFormat(); + static QArray<DateFormat> formatOptions(); // qtopia 1.6.0 + + static void connectChange(QObject*,const char* member); + static void disconnectChange(QObject*,const char* member); - /** @name Do not use as they don't honor system settings for AMPM - * - */ - //@{ - static QString dateString( const QDateTime &t, bool ampm = false ); + // Not recommended to call these (they don't honor system ampm) + static QString dateString( const QDateTime &t, bool ampm ); static QString timeString( const QTime &t, bool ampm, bool seconds ); - static QString timeString( const QTime &t, bool ampm = false ); + static QString timeString( const QTime &t, bool ampm ); static QString shortTime( bool ampm, bool seconds ); - static QString shortTime( bool ampm = false ); - //@} + static QString shortTime( bool ampm ); static QString numberDateString( const QDate &d, DateFormat ); static QString numberDateString( const QDate &d ) { return numberDateString( d, currentDateFormat() ); } static QString longNumberDateString( const QDate &d, DateFormat ); static QString longNumberDateString( const QDate &d ) { return longNumberDateString( d, currentDateFormat() ); } static QString shortDate( const QDate &, DateFormat ); static QString dateString( const QDate &, DateFormat ); static QString longDateString( const QDate &, DateFormat ); - static DateFormat currentDateFormat(); - private: static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat ); - + }; #endif |