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

📄 global.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.7平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ 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#ifndef QTOPIA_INTERNAL_FILEOPERATIONS#define QTOPIA_INTERNAL_FILEOPERATIONS#endif#include <qtopia/global.h>#ifdef Q_WS_QWS#include <qtopia/qpedebug.h>#include <qtopia/qdawg.h>#include <qtopia/qpeapplication.h>#include <qtopia/resource.h>#include <qtopia/storage.h>#include <qtopia/applnk.h>#endif#if defined(Q_WS_QWS) && !defined(QT_NO_COP)#include <qtopia/qcopenvelope_qws.h>#endif#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 <qdatetime.h>#ifdef QTOPIA_DESKTOP#include <qsettings.h>#endif#ifndef Q_OS_WIN32#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <qfileinfo.h>#else#include <sys/locking.h>#include <io.h>#include <string.h> // for strerror function#include <stdlib.h>#endif#include <stdlib.h>#include <stdio.h>#include <errno.h>extern bool mkdirRecursive( QString path );// added in qtopia 1.6, so don't export thisQString qtopia_tempName( const QString &fname ){    QString temp;#ifndef Q_OS_WIN32    temp = fname + ".new";#else    QFileInfo fileInfo( fname );    temp = fileInfo.dirPath( TRUE ) + "/" + fileInfo.baseName() +		 "_new." + fileInfo.extension(); // No tr#endif    return temp;}bool qtopia_renameFile( QString from, QString to ){    if ( from.isEmpty() || to.isEmpty() ) {	qWarning("qtopia_renameFile emptry string(s) from '%s' to '%s'",		 from.latin1(), to.latin1() );	return FALSE;    }    // now do the rename#ifdef Q_OS_WIN32    if ( QFile::exists( to ) && !QFile::remove( to ) )	qWarning("Global::renameFile failed removing %s before rename", to.latin1() );#endif    QDir dir;    if ( dir.rename( from, to ) )	return TRUE;    qWarning( "problem renaming file using qdir::rename %s to %s",	      from.latin1(), to.latin1() );    //QFile::remove( from );    // return FALSE;    from = QDir::convertSeparators( QDir::cleanDirPath( from ) );    to = QDir::convertSeparators( QDir::cleanDirPath( to ) );    if ( ::rename( from, to ) != 0 ) { 	qWarning( "::rename problem renaming file %s to %s errno %d",	 	  from.latin1(), to.latin1(), errno );#ifdef Q_OS_WIN32 	qWarning("\trename error = %s", strerror(NULL) );#endif	return FALSE;    }    qDebug("worked using ::rename");    return TRUE;}#ifdef Q_WS_QWSGlobal::Command* Global::builtin=0;QGuardedPtr<QWidget> *Global::running=0;//#include "quickexec_p.h"class Emitter : public QObject {    Q_OBJECTpublic:    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&);};static bool docDirCreated = FALSE;static QDawg* fixed_dawg = 0;static QDict<QDawg> *named_dawg = 0;static QString dictDir(){    return QPEApplication::qpeDir() + "etc/dict";}/*!  \class Global global.h  \brief The Global class provides application-wide global functions.  The Global functions are grouped as follows:  \tableofcontents  \section1 User Interface  The statusMessage() function provides short-duration messages to the  user. The showInputMethod() function shows the current input method,  and hideInputMethod() hides the input method.  \section1 Document related  The findDocuments() function creates a set of \link doclnk.html  DocLnk\endlink objects in a particular folder.  \section1 Filesystem related  Global provides an applicationFileName() function that returns the  full path of an application-specific file.  The execute() function runs an application.  \section1 Word list related  A list of words relevant to the current locale is maintained by the  system. The list is held in a \link qdawg.html DAWG\endlink  (implemented by the QDawg class). This list is used, for example, by  the pickboard input method.  The global QDawg is returned by fixedDawg(); this cannot be updated.  An updatable copy of the global QDawg is returned by addedDawg().  Applications may have their own word lists stored in \l{QDawg}s  which are returned by dawg(). Use addWords() to add words to the  updateable copy of the global QDawg or to named application  \l{QDawg}s.  \section1 Quoting  The shellQuote() function quotes a string suitable for passing to a  shell. The stringQuote() function backslash escapes '\' and '"'  characters.  \section1 Hardware  The writeHWClock() function sets the hardware clock to the system  clock's date and time.  \ingroup qtopiaemb*//*!  \internal*/Global::Global(){}/*!  Returns the unchangeable QDawg that contains general  words for the current locale.  \sa addedDawg()*/const QDawg& Global::fixedDawg(){    if ( !fixed_dawg ) {	if ( !docDirCreated )	    createDocDir();	fixed_dawg = new QDawg;	QString dawgfilename = dictDir() + "/dawg";	QString words_lang;	QStringList langs = Global::languageList();	for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {	    QString lang = *it;	    words_lang = dictDir() + "/words." + lang;	    QString dawgfilename_lang = dawgfilename + "." + lang;	    if ( QFile::exists(dawgfilename_lang) ||		 QFile::exists(words_lang) ) {		dawgfilename = dawgfilename_lang;		break;	    }	}	QFile dawgfile(dawgfilename);	if ( !dawgfile.exists() ) {	    QString fn = dictDir() + "/words";	    if ( QFile::exists(words_lang) )		fn = words_lang;	    QFile in(fn);	    if ( in.open(IO_ReadOnly) ) {		fixed_dawg->createFromWords(&in);		dawgfile.open(IO_WriteOnly);		fixed_dawg->write(&dawgfile);		dawgfile.close();	    }	} else {	    fixed_dawg->readFile(dawgfilename);	}    }    return *fixed_dawg;}/*!  Returns the changeable QDawg that contains general  words for the current locale.  \sa fixedDawg()*/const QDawg& Global::addedDawg(){    return dawg("local"); // No tr}/*!  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"; // No tr	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); // No tr}/*!  Adds \a wordlist to the dawg() named \a dictname.  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"; // No tr    QString dawgfilenamenew = dawgfilename + ".new";    QFile dawgfile(dawgfilenamenew);    if ( dawgfile.open(IO_WriteOnly) ) {	d.write(&dawgfile);	dawgfile.close();	qtopia_renameFile(dawgfilenamenew,dawgfilename);    }    // #### Re-read the dawg here if we use mmap().    // #### Signal other processes to re-read.}/*!  \internal*/void Global::createDocDir(){    if ( !docDirCreated ) {	QDir d;	if (!d.exists(QPEApplication::documentDir().latin1())){	    docDirCreated = TRUE;#ifndef Q_WS_WIN32	    mkdir( QPEApplication::documentDir().latin1(), 0755 );#else	    mkdirRecursive(QPEApplication::documentDir());#endif	}else{	    docDirCreated = TRUE;	}    }}/*!  \internal*/void Global::applyStyle(){#ifndef 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 ){#ifndef QT_NO_COP    QCopChannel::send( "QPE/System", "shutdown()" );#endif    return 0;}/*!  \internal*/QWidget *Global::restart( bool ){#if defined(Q_WS_QWS) && !defined(QT_NO_COP)    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(){#ifndef 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(){#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*/

⌨️ 快捷键说明

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