⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*!  \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.  \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/System", "execute(QString)" );	e << c;    } else {	QCopEnvelope e( "QPE/System", "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;#ifdef QTOPIA_DESKTOP    QSettings settings;    settings.insertSearchPath( QSettings::Unix,	    QDir::homeDirPath() + "/.palmtopcenter/" );    settings.insertSearchPath( QSettings::Windows, "/Trolltech" );    lang = settings.readEntry( "/palmtopcenter/language" );#endif    if (lang.isEmpty())	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;}#ifdef Q_WS_QWSQStringList Global::helpPath(){    QStringList path;    QStringList langs = Global::languageList();    for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {	QString lang = *it;	if ( !lang.isEmpty() )	    path += QPEApplication::qpeDir() + "help/" + lang + "/html";    }    path += QPEApplication::qpeDir() + "pics";    path += QPEApplication::qpeDir() + "help/html";    path += QPEApplication::qpeDir() + "docs";    return path;}#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 = QDir::homeDirPath();#ifdef QTOPIA_DESKTOP    r += "/.palmtopcenter/";#else    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;#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/*!  /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    result = "/tmp/";#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;}#ifdef Q_WS_QWS  /*! \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#include "global.moc"#endif#endif  //qws

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -