summaryrefslogtreecommitdiff
path: root/library/global.cpp
Side-by-side diff
Diffstat (limited to 'library/global.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/global.cpp141
1 files changed, 112 insertions, 29 deletions
diff --git a/library/global.cpp b/library/global.cpp
index ab27b3f..7438891 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,16 +1,16 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** 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
@@ -36,25 +36,27 @@
#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>
+#ifdef QWS
#include <qwindowsystem_qws.h> // for qwsServer
+#endif
#include <qdatetime.h>
#include <qfile.h>
namespace {
// checks if the storage should be searched
bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke
QFile file(path );
if(!file.open(IO_ReadOnly ) )
return true;
QByteArray array = file.readAll();
@@ -99,29 +101,31 @@ private slots:
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 )
{
+#ifdef QWS
#if QT_VERSION >= 232 && !defined(QT_NO_COP)
connect( qwsServer, SIGNAL( newChannel(const QString&)),
this, SLOT( handleNewChannel(const QString&)) );
dict.setAutoDelete( TRUE );
#endif
+#endif
}
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
}
@@ -160,25 +164,73 @@ 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 collects application-wide global functions.
+ \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.
@@ -243,68 +295,78 @@ const QDawg& Global::addedDawg()
\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 = dictDir() + "/" + name + ".dawg";
+ 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);
}
/*!
- Adds \a wordlist to the dawg() named \a dictname.
+ \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 = dictDir() + "/" + dictname + ".dawg";
+ 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 a full path for the application named \a appname, with the
- given \a filename or QString::null if there was a problem creating
+ 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 those directories exist.
+ 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 )
@@ -317,26 +379,26 @@ QString Global::applicationFileName(const QString& appname, const QString& filen
\internal
*/
void Global::createDocDir()
{
if ( !docDirCreated ) {
docDirCreated = TRUE;
mkdir( QPEApplication::documentDir().latin1(), 0755 );
}
}
/*!
- Displays a status \a message to the user. This generally appears
- in the taskbar for some amount of time, then disappears.
+ 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
}
/*!
\internal
*/
@@ -364,34 +426,46 @@ QWidget *Global::shutdown( bool )
\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()
{
#if defined(Q_WS_QWS) && !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(Q_WS_QWS) && !defined(QT_NO_COP)
QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
#endif
}
/*!
\internal
*/
@@ -456,32 +530,38 @@ bool Global::terminateBuiltin( const QString& n )
}
}
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. Not recommended.
+ 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(Q_WS_QWS) && !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() ) ) {
QCopEnvelope e("QPE/System", "notBusy(QString)" );
@@ -532,29 +612,31 @@ void Global::invoke(const QString &c)
::close( fd );
::setpgid( ::getpid(), ::getppid() );
// Try bindir first, so that foo/bar works too
::execv( qpeDir()+"/bin/"+args[0], (char * const *)args );
::execvp( args[0], (char * const *)args );
_exit( -1 );
}
}
StartingAppList::add( list[0] );
#endif //QT_NO_QWS_MULTIPROCESS
}
+
/*!
- Executes application identfied by \a c, passing \a document.
+ Executes the application identfied by \a c, passing \a
+ document if it isn't null.
- Note that you might be better off sending a QCop message to
- the application's QPE/Application/<i>appname</i> channel.
+ Note that a better approach might be to send a QCop message to the
+ application's QPE/Application/\e{appname} channel.
*/
void Global::execute( const QString &c, const QString& document )
{
if ( qApp->type() != QApplication::GuiServer ) {
// ask the server to do the work
#if defined(Q_WS_QWS) && !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;
@@ -568,77 +650,84 @@ void Global::execute( const QString &c, const QString& document )
if (builtin) {
for (int i = 0; builtin[i].file; i++) {
if ( builtin[i].file == c ) {
if ( running[i] ) {
if ( !document.isNull() && builtin[i].documentary )
setDocument(running[i], document);
running[i]->raise();
running[i]->show();
running[i]->setActiveWindow();
} else {
running[i] = builtin[i].func( builtin[i].maximized );
}
+#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "notBusy(QString)" );
e << c; // that was quick ;-)
+#endif
return;
}
}
}
//Global::invoke(c, document);
// Convert the command line in to a list of arguments
QStringList list = QStringList::split(QRegExp(" *"),c);
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
QString ap=list[0];
qDebug("executing %s", ap.latin1() );
if ( ap == "suspend" ) {
QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
return;
}
/* if need be, sending a qcop message will result in an invoke, see
preceeding function */
- { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
+ invoke( ap );
+ //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
if ( !document.isEmpty() ) {
QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" );
env << document;
}
#endif
}
/*!
- Returns the string \a s with the characters backslash, ", and $
- quoted by a preceeding backslash.
+ 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 backslash and "
- quoted by a preceeding backslash.
+ 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];
}
@@ -704,27 +793,21 @@ QStringList Global::languageList()
}
QStringList 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/en/html";
+ path += QPEApplication::qpeDir() + "/help/html";
path += QPEApplication::qpeDir() + "/docs";
- QString dir = QDir::current().canonicalPath();
- if ( dir == "/" )
- dir += "/docs";
- else {
- path += dir + "/../pics";
- dir += "/../docs";
- path += dir;
- }
+
+
return path;
}
#include "global.moc"