📄 global.cpp
字号:
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(){#ifndef 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;}/*! \class Global::Command \brief The Global::Command class is internal. \internal*/void Global::removeRunningArray(){ if ( running ) delete [] running; running = 0;}/*! \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 ]; qAddPostRoutine( removeRunningArray );}/*! \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. \warning Do not use this function. Use execute instead. \sa execute()*/void Global::invoke(const QString &){ qDebug("Global::invoke does not work anymore");}/*! 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 ){#ifndef QT_NO_COP if ( document.isNull() ) { QCopEnvelope e( "QPE/Server", "execute(QString)" ); e << c; } else { QCopEnvelope e( "QPE/Server", "execute(QString,QString)" ); e << c << document; }#endif return;}#endif/*! Returns the string \a s with the characters '\', '"', and '$' quoted by a preceeding '\', and enclosed by double-quotes ("). \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;}#ifdef Q_WS_QWS/*! Finds all documents in the system's document directories which match the filter \a mimefilter, and appends the resulting \link doclnk.html DocLnk\endlink objects to \a folder.*/void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter){ QString homedocs = QPEApplication::documentDir(); DocLnkSet d(homedocs,mimefilter); folder->appendFrom(d); StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it ( fs ); for ( ; it.current(); ++it ) { if ( (*it)->isRemovable() ) { QString path = (*it)->path(); DocLnkSet ide( path, mimefilter ); folder->appendFrom(ide); } }}#endif // Q_WS_QWSQStringList Global::languageList(){ QString lang; QStringList langs;#ifdef QTOPIA_DESKTOP langs = gQtopiaDesktopConfig->languages();#else if (lang.isEmpty()) lang = getenv("LANG"); int i = lang.find("."); if ( i > 0 ) lang = lang.left( i ); langs.append(lang); i = lang.find( "_" ); if ( i > 0 ) langs.append(lang.left(i));#endif return langs;}#ifdef Q_WS_QWS#include "global_qtopiapaths.cpp"QStringList Global::helpPath(){ QStringList path; QStringList langs = Global::languageList(); QStringList qpepaths = global_qtopiapaths(); for (QStringList::ConstIterator qit = qpepaths.begin(); qit!=qpepaths.end(); ++qit) { for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { QString lang = *it; if ( !lang.isEmpty() ) path += *qit + "help/" + lang + "/html"; } path += *qit + "pics"; path += *qit + "help/html"; path += *qit + "docs"; } return path;}#endif/*! 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 = ::qpe_homeDirPath();#ifndef QTOPIA_DESKTOP r += "/Applications/";#endif 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; //qDebug("Global::applicationFileName = %s", r.latin1()); return r;}/*! Displays a status \a message to the user. This usually appears in the taskbar for a short amount of time, then disappears.*/void Global::statusMessage(const QString& message){#if defined(Q_WS_QWS) && !defined(QT_NO_COP) QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); e << message;#else Q_UNUSED( message );#endif}#ifdef QTOPIA_INTERNAL_FILEOPERATIONS#ifdef Q_OS_WIN32bool Global::truncateFile(QFile &f, int size){ if (!f.isOpen()) return FALSE; if (size == -1) size = f.size(); if (::chsize(f.handle(), size) != -1) return TRUE; else return FALSE;}#else // Q_OS_WIN32/*! \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;}#endif // Q_OS_WIN32#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#if (defined(QTOPIA_INTERNAL_FILEOPERATIONS) && defined(Q_WS_QWS)) || defined(QTOPIA_DESKTOP) /*! \enum Global::Lockflags \internal This enum controls what type of locking is performed on file. Current defined values are: \value LockShare Allow lock to be shared. Reserved for future use \value LockWrite Create at a write lock. \value LockBlock Block the process when lock is encountered. Under WIN32 this blocking is limited to ten(10) failed attempts to access locked file. Reserved for future use. */#ifndef Q_OS_WIN32/*! \internal Lock region of file. Any locks created should be released before the program exits. Returns TRUE if sucessfull \a f must be an open file \a flags any combination of LockShare, LockWrite, LockBlock */bool Global::lockFile(QFile &f, int flags){ struct flock fileLock; if (!f.isOpen()) return FALSE; fileLock.l_whence = SEEK_SET; fileLock.l_start = 0; int lockCommand, lockMode; fileLock.l_len = f.size(); if (flags == -1){ lockMode = F_RDLCK; if (f.mode() == IO_ReadOnly) fileLock.l_type = F_RDLCK; else fileLock.l_type = F_WRLCK; lockCommand = F_SETLK; }else{ if (flags & Global::LockWrite) fileLock.l_type = F_WRLCK; else fileLock.l_type = F_RDLCK; if (flags & Global::LockBlock) lockCommand = F_SETLK; else lockCommand = F_SETLKW; // block process if possible } if (::fcntl(f.handle(), lockCommand, &fileLock) != -1) return TRUE; else return FALSE;}/*! \internal Unlock a region of file \a f must be an open file previously locked */bool Global::unlockFile(QFile &f){ struct flock fileLock; if (!f.isOpen()) return FALSE; fileLock.l_whence = SEEK_SET; fileLock.l_start = 0; fileLock.l_len = f.size(); fileLock.l_type = F_UNLCK; if (::fcntl(f.handle(), F_SETLK, &fileLock) != -1) return TRUE; else return FALSE;}/*! \internal Could a request to lock file with given flags succeed \a f must be an opened file \a flags the desired lock type required*/bool Global::isFileLocked(QFile &f, int /* flags */){ struct flock fileLock; if (!f.isOpen()) return FALSE; fileLock.l_whence = SEEK_SET; fileLock.l_start = 0; fileLock.l_len = f.size(); if (f.mode() == IO_ReadOnly) fileLock.l_type = F_RDLCK; else fileLock.l_type = F_WRLCK; fileLock.l_pid = 0; if (::fcntl(f.handle(), F_SETLK, &fileLock) != -1) return FALSE; return fileLock.l_pid != 0;}#elsebool Global::lockFile(QFile &f, int flags){ // If the file has been opened then a lock has been achieved return f.isOpen();}bool Global::unlockFile(QFile &f){ // No need to do anything as we do not open file using sharing return TRUE;}bool Global::isFileLocked(QFile &f, int flags){ // if the file is open then we must have achieved a file lock return f.isOpen();}#endif#endifQString qtopia_internal_homeDirPath(){ return ::qpe_homeDirPath();}#include "../qtopia2/qpe_defaultButtonsFile.cpp"QString qtopia_internal_defaultButtonsFile(){ return ::qpe_defaultButtonsFile();}#ifdef Q_WS_QWS#include "global.moc"#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -