summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-16 01:09:22 (UTC)
committer zecke <zecke>2002-10-16 01:09:22 (UTC)
commit543e54de7170c606b6883ac4152567e7faf13182 (patch) (side-by-side diff)
tree8a7d623e96cab0135a2f7cb11aa9f7491bfda9a2
parent3e973543b77631d053a9616b5540966dbe51ab47 (diff)
downloadopie-543e54de7170c606b6883ac4152567e7faf13182.zip
opie-543e54de7170c606b6883ac4152567e7faf13182.tar.gz
opie-543e54de7170c606b6883ac4152567e7faf13182.tar.bz2
Remove #ifdef QWS HELL
a Platform which is not supporting IPC compatible to QCopChannel/Envelope is not of much use nowadays.. so be sure your platform is supporting it
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/alarmserver.cpp2
-rw-r--r--library/applnk.cpp4
-rw-r--r--library/fileselector.cpp2
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/fontmanager.cpp2
-rw-r--r--library/global.cpp28
-rw-r--r--library/ir.cpp2
-rw-r--r--library/lnkproperties.cpp2
-rw-r--r--library/network.cpp2
-rw-r--r--library/networkinterface.cpp2
-rw-r--r--library/password.cpp2
-rw-r--r--library/qpedecoration_qws.cpp2
-rw-r--r--library/tzselect.cpp4
13 files changed, 11 insertions, 45 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 177a0cb..02bca3d 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,289 +1,287 @@
/**********************************************************************
** 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 <qdir.h>
#include <qfile.h>
#include <qmessagebox.h>
#include <qtextstream.h>
#include <qpe/qpeapplication.h>
#include "global.h"
#include "resource.h"
-#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
#include <qpe/qcopenvelope_qws.h>
-#endif
#include "alarmserver.h"
#include <qpe/timeconversion.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
struct timerEventItem {
time_t UTCtime;
QCString channel, message;
int data;
bool operator==( const timerEventItem &right ) const
{
return ( UTCtime == right.UTCtime
&& channel == right.channel
&& message == right.message
&& data == right.data );
}
};
class TimerReceiverObject : public QObject
{
public:
TimerReceiverObject() { }
~TimerReceiverObject() { }
void resetTimer();
void setTimerEventItem();
void deleteTimer();
protected:
void timerEvent( QTimerEvent *te );
private:
QString atfilename;
};
TimerReceiverObject *timerEventReceiver = NULL;
QList<timerEventItem> timerEventList;
timerEventItem *nearestTimerEvent = NULL;
// set the timer to go off on the next event in the list
void setNearestTimerEvent()
{
nearestTimerEvent = NULL;
QListIterator<timerEventItem> it( timerEventList );
if ( *it )
nearestTimerEvent = *it;
for ( ; *it; ++it )
if ( (*it)->UTCtime < nearestTimerEvent->UTCtime )
nearestTimerEvent = *it;
if (nearestTimerEvent)
timerEventReceiver->resetTimer();
else
timerEventReceiver->deleteTimer();
}
//store current state to file
//Simple implementation. Should run on a timer.
static void saveState()
{
QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
if ( timerEventList.isEmpty() ) {
unlink( savefilename );
return;
}
QFile savefile(savefilename+".new");
if ( savefile.open(IO_WriteOnly) ) {
QDataStream ds( &savefile );
//save
QListIterator<timerEventItem> it( timerEventList );
for ( ; *it; ++it ) {
ds << it.current()->UTCtime;
ds << it.current()->channel;
ds << it.current()->message;
ds << it.current()->data;
}
savefile.close();
unlink( savefilename );
QDir d; d.rename(savefilename+".new",savefilename);
}
}
/*!
Sets up the alarm server. Restoring to previous state (session management).
*/
void AlarmServer::initialize()
{
//read autosave file and put events in timerEventList
QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
QFile savefile(savefilename);
if ( savefile.open(IO_ReadOnly) ) {
QDataStream ds( &savefile );
while ( !ds.atEnd() ) {
timerEventItem *newTimerEventItem = new timerEventItem;
ds >> newTimerEventItem->UTCtime;
ds >> newTimerEventItem->channel;
ds >> newTimerEventItem->message;
ds >> newTimerEventItem->data;
timerEventList.append( newTimerEventItem );
}
savefile.close();
if (!timerEventReceiver)
timerEventReceiver = new TimerReceiverObject;
setNearestTimerEvent();
}
}
static const char* atdir = "/var/spool/at/";
static bool triggerAtd( bool writeHWClock = FALSE )
{
QFile trigger(QString(atdir) + "trigger");
if ( trigger.open(IO_WriteOnly|IO_Raw) ) {
const char* data =
#ifdef QT_QWS_CUSTOM
//custom atd only writes HW Clock if we write a 'W'
( writeHWClock ) ? "W\n" :
#endif
data = "\n";
int len = strlen(data);
int total_written = trigger.writeBlock(data,len);
if ( total_written != len ) {
QMessageBox::critical( 0, QObject::tr( "Out of Space" ),
QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) );
trigger.close();
QFile::remove( trigger.name() );
return FALSE;
}
return TRUE;
}
return FALSE;
}
void TimerReceiverObject::deleteTimer()
{
if ( !atfilename.isEmpty() ) {
unlink( atfilename );
atfilename = QString::null;
triggerAtd( FALSE );
}
}
void TimerReceiverObject::resetTimer()
{
const int maxsecs = 2147000;
int total_written;
QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime);
QDateTime now = QDateTime::currentDateTime();
if ( nearest < now )
nearest = now;
int secs = TimeConversion::secsTo( now, nearest );
if ( secs > maxsecs ) {
// too far for millisecond timing
secs = maxsecs;
}
// System timer (needed so that we wake from deep sleep),
// from the Epoch in seconds.
//
int at_secs = TimeConversion::toUTC(nearest);
// qDebug("reset timer to %d seconds from Epoch",at_secs);
QString fn = atdir + QString::number(at_secs) + "."
+ QString::number(getpid());
if ( fn != atfilename ) {
QFile atfile(fn+".new");
if ( atfile.open(IO_WriteOnly|IO_Raw) ) {
// just wake up and delete the at file
QString cmd = "#!/bin/sh\nrm " + fn;
total_written = atfile.writeBlock(cmd.latin1(),cmd.length());
if ( total_written != int(cmd.length()) ) {
QMessageBox::critical( 0, tr("Out of Space"),
tr("Unable to schedule alarm.\n"
"Please free up space and try again") );
atfile.close();
QFile::remove( atfile.name() );
return;
}
atfile.close();
unlink( atfilename );
QDir d; d.rename(fn+".new",fn);
chmod(fn.latin1(),0755);
atfilename = fn;
triggerAtd( FALSE );
} else {
qWarning("Cannot open atd file %s",fn.latin1());
}
}
// Qt timers (does the actual alarm)
// from now in milliseconds
//
qDebug("AlarmServer waiting %d seconds",secs);
startTimer( 1000 * secs + 500 );
}
void TimerReceiverObject::timerEvent( QTimerEvent * )
{
bool needSave = FALSE;
killTimers();
if (nearestTimerEvent) {
if ( nearestTimerEvent->UTCtime
<= TimeConversion::toUTC(QDateTime::currentDateTime()) ) {
#ifndef QT_NO_COP
QCopEnvelope e( nearestTimerEvent->channel,
nearestTimerEvent->message );
e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime )
<< nearestTimerEvent->data;
#endif
timerEventList.remove( nearestTimerEvent );
needSave = TRUE;
}
setNearestTimerEvent();
} else {
resetTimer();
}
if ( needSave )
saveState();
}
/*!
\class AlarmServer alarmserver.h
\brief The AlarmServer class allows alarms to be scheduled and unscheduled.
Applications can schedule alarms with addAlarm() and can
unschedule alarms with deleteAlarm(). When the time for an alarm
to go off is reached the specified \link qcop.html QCop\endlink
message is sent on the specified channel (optionally with
additional data).
Scheduling an alarm using this class is important (rather just using
a QTimer) since the machine may be asleep and needs to get woken up using
the Linux kernel which implements this at the kernel level to minimize
battery usage while asleep.
\ingroup qtopiaemb
\sa QCopEnvelope
*/
/*!
Schedules an alarm to go off at (or soon after) time \a when. When
the alarm goes off, the \link qcop.html QCop\endlink \a message will
be sent to \a channel, with \a data as a parameter.
diff --git a/library/applnk.cpp b/library/applnk.cpp
index a56da5d..5763c62 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,301 +1,297 @@
/**********************************************************************
** 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_MIMEEXT
#define QTOPIA_INTERNAL_PRELOADACCESS
#define QTOPIA_INTERNAL_APPLNKASSIGN
#include "applnk.h"
#include <qpe/qpeapplication.h>
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
-#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
-#endif
#include <qpe/global.h>
#include <qpe/mimetype.h>
#include <qpe/config.h>
#include <qpe/storage.h>
#include <qpe/resource.h>
#include <qdict.h>
#include <qdir.h>
#include <qregexp.h>
-#ifdef Q_WS_QWS
#include <qgfx_qws.h>
-#endif
#include <stdlib.h>
int AppLnk::lastId = 5000;
static int smallSize = 14;
static int bigSize = 32;
static QString safeFileName(const QString& n)
{
QString safename=n;
safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
safename.replace(QRegExp("^[^A-Za-z]*"),"");
if ( safename.isEmpty() )
safename = "_";
return safename;
}
static bool prepareDirectories(const QString& lf)
{
if ( !QFile::exists(lf) ) {
// May need to create directories
QFileInfo fi(lf);
if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
return FALSE;
}
return TRUE;
}
class AppLnkPrivate
{
public:
/* the size of the Pixmap */
enum Size {Normal = 0, Big };
AppLnkPrivate() {
/* we want one normal and one big item */
QPixmap pix;
mPixmaps.insert(0, pix );
mPixmaps.insert(1, pix);
}
QStringList mCatList; // always correct
QArray<int> mCat; // cached value; correct if not empty
QMap<int, QPixmap> mPixmaps;
void updateCatListFromArray()
{
Categories cat( 0 );
cat.load( categoryFileName() );
mCatList = cat.labels("Document View",mCat);
}
void setCatArrayDirty()
{
mCat.resize(0);
}
void ensureCatArray()
{
if ( mCat.count() > 0 || mCatList.count()==0 )
return;
Categories cat( 0 );
cat.load( categoryFileName() );
mCat.resize( mCatList.count() );
int i;
QStringList::ConstIterator it;
for ( i = 0, it = mCatList.begin(); it != mCatList.end();
++it, i++ ) {
bool number;
int id = (*it).toInt( &number );
if ( !number ) {
id = cat.id( "Document View", *it );
if ( id == 0 )
id = cat.addCategory( "Document View", *it );
}
mCat[i] = id;
}
}
};
/*!
\class AppLnk applnk.h
\brief The AppLnk class represents an application available on the system.
Every Qtopia application \e app has a corresponding \e app.desktop
file. When one of these files is read its data is stored as an
AppLnk object.
The AppLnk class introduces some Qtopia-specific concepts, and
provides a variety of functions, as described in the following
sections.
\tableofcontents
\target Types
\section1 Types
Every AppLnk object has a \e type. For applications, games and
settings the type is \c Application; for documents the
type is the document's MIME type.
\target files-and-links
\section1 Files and Links
When you create an AppLnk (or more likely, a \link doclnk.html
DocLnk\endlink), you don't deal directly with filenames in the
filesystem. Instead you do this:
\code
DocLnk d;
d.setType("text/plain");
d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
\endcode
At this point, the file() and linkFile() are unknown. Normally
this is uninteresting, and the names become automatically known,
and more importantly, becomes reserved, when you ask what they are:
\code
QString fn = d.file();
\endcode
This invents a filename, and creates the file on disk (an empty
reservation file) to prevent the name being used by another
application.
In some circumstances, you don't want to create the file if it
doesn't already exist (e.g. in the Document tab, some of the \link
doclnk.html DocLnk\endlink objects represented by icons are
DocLnk's created just for that view - they don't have
corresponding \c .desktop files. To avoid littering empty
reservation files around, we check in a few places to see whether
the file really needs to exist).
\section1 Functionality
AppLnk objects are created by calling the constructor with the
name of a \e .desktop file. The object can be checked for validity
using isValid().
The following functions are used to set or retrieve information
about the application:
\table
\header \i Get Function \i Set Function \i Short Description
\row \i \l name() \i \l setName() \i application's name
\row \i \l pixmap() \i \e none \i application's icon
\row \i \l bigPixmap() \i \e none \i application's large icon
\row \i \e none \i setIcon() \i sets the icon's filename
\row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
\row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
\row \i \l comment() \i \l setComment() \i text for the Details dialog
\row \i \l exec() \i \l setExec() \i executable's filename
\row \i \l file() \i \e none \i document's filename
\row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename
\row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
\row \i \l categories() \i \l setCategories() \i \e{see the function descriptions}
\row \i \l fileKnown() \i \e none \i see \link
#files-and-links Files and Links\endlink above
\row \i \l linkFileKnown() \i \e none \i see \link
#files-and-links Files and Links\endlink above
\row \i \l property() \i \l setProperty() \i any AppLnk property
can be retrieved or set (if writeable) using these
\endtable
To save an AppLnk to disk use writeLink(). To execute the
application that the AppLnk object refers to, use execute().
AppLnk's can be deleted from disk using removeLinkFile(). To
remove both the link and the application's executable use
removeFiles().
Icon sizes can be globally changed (but only for AppLnk objects
created after the calls) with setSmallIconSize() and
setBigIconSize().
\ingroup qtopiaemb
*/
/*!
Sets the size used for small icons to \a small pixels.
Only affects AppLnk objects created after the call.
\sa smallIconSize() setIcon()
*/
void AppLnk::setSmallIconSize(int small)
{
smallSize = small;
}
/*!
Returns the size used for small icons.
\sa setSmallIconSize() setIcon()
*/
int AppLnk::smallIconSize()
{
return smallSize;
}
/*!
Sets the size used for large icons to \a big pixels.
Only affects AppLnk objects created after the call.
\sa bigIconSize() setIcon()
*/
void AppLnk::setBigIconSize(int big)
{
bigSize = big;
}
/*!
Returns the size used for large icons.
\sa setBigIconSize() setIcon()
*/
int AppLnk::bigIconSize()
{
return bigSize;
}
/*!
\fn QString AppLnk::name() const
Returns the Name property. This is the user-visible name for the
document or application, not the filename.
See \link #files-and-links Files and Links\endlink.
\sa setName()
*/
/*!
\fn QString AppLnk::exec() const
Returns the Exec property. This is the name of the executable
program associated with the AppLnk.
\sa setExec()
*/
/*!
\fn QString AppLnk::rotation() const
Returns the Rotation property. The value is 0, 90, 180 or 270
degrees.
*/
/*!
\fn QString AppLnk::comment() const
Returns the Comment property.
\sa setComment()
*/
/*!
\fn QStringList AppLnk::mimeTypes() const
Returns the MimeTypes property. This is the list of MIME types
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 052a29e..4039243 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,291 +1,289 @@
/**********************************************************************
** 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.
**
**********************************************************************/
// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
// have this class.
#define QTOPIA_INTERNAL_FSLP
#include "fileselector.h"
#include "fileselector_p.h"
#include "global.h"
#include "resource.h"
#include "config.h"
#include "applnk.h"
#include "storage.h"
#include "qpemenubar.h"
-#ifdef QWS
#include <qcopchannel_qws.h>
-#endif
#include "lnkproperties.h"
#include "applnk.h"
#include <qpe/qpeapplication.h>
#include "categorymenu.h"
#include "categoryselect.h"
#include "mimetype.h"
#include <qpe/categories.h>
#include <stdlib.h>
#include <qdir.h>
#include <qwidget.h>
#include <qpopupmenu.h>
#include <qtoolbutton.h>
#include <qpushbutton.h>
#include <qheader.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
class TypeCombo : public QComboBox
{
Q_OBJECT
public:
TypeCombo( QWidget *parent, const char *name=0 )
: QComboBox( parent, name )
{
connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );
}
void reread( DocLnkSet &files, const QString &filter );
signals:
void selected( const QString & );
protected slots:
void selectType( int idx ) {
emit selected( typelist[idx] );
}
protected:
QStringList typelist;
QString prev;
};
void TypeCombo::reread( DocLnkSet &files, const QString &filter )
{
typelist.clear();
QStringList filters = QStringList::split( ';', filter );
int pos = filter.find( '/' );
//### do for each filter
if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {
typelist.append( filter );
clear();
QString minor = filter.mid( pos+1 );
minor[0] = minor[0].upper();
insertItem( tr("%1 files").arg(minor) );
setCurrentItem(0);
setEnabled( FALSE );
return;
}
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if ( !typelist.contains( (*dit)->type() ) )
typelist.append( (*dit)->type() );
}
QStringList types;
QStringList::ConstIterator it;
for (it = typelist.begin(); it!=typelist.end(); ++it) {
QString t = *it;
if ( t.left(12) == "application/" ) {
MimeType mt(t);
const AppLnk* app = mt.application();
if ( app )
t = app->name();
else
t = t.mid(12);
} else {
QString major, minor;
int pos = t.find( '/' );
if ( pos >= 0 ) {
major = t.left( pos );
minor = t.mid( pos+1 );
}
if ( minor.find( "x-" ) == 0 )
minor = minor.mid( 2 );
minor[0] = minor[0].upper();
major[0] = major[0].upper();
if ( filters.count() > 1 )
t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);
else
t = minor;
}
types += tr("%1 files").arg(t);
}
for (it = filters.begin(); it!=filters.end(); ++it) {
typelist.append( *it );
int pos = (*it).find( '/' );
if ( pos >= 0 ) {
QString maj = (*it).left( pos );
maj[0] = maj[0].upper();
types << tr("All %1 files").arg(maj);
}
}
if ( filters.count() > 1 ) {
typelist.append( filter );
types << tr("All files");
}
prev = currentText();
clear();
insertStringList(types);
for (int i=0; i<count(); i++) {
if ( text(i) == prev ) {
setCurrentItem(i);
break;
}
}
if ( prev.isNull() )
setCurrentItem(count()-1);
setEnabled( TRUE );
}
//===========================================================================
FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
: QListViewItem( parent ), fl( f )
{
setText( 0, f.name() );
setPixmap( 0, f.pixmap() );
}
FileSelectorItem::~FileSelectorItem()
{
}
FileSelectorView::FileSelectorView( QWidget *parent, const char *name )
: QListView( parent, name )
{
setAllColumnsShowFocus( TRUE );
addColumn( tr( "Name" ) );
header()->hide();
}
FileSelectorView::~FileSelectorView()
{
}
void FileSelectorView::keyPressEvent( QKeyEvent *e )
{
QString txt = e->text();
if (e->key() == Key_Space)
emit returnPressed( currentItem() );
else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
e->ignore();
else
QListView::keyPressEvent(e);
}
class NewDocItem : public FileSelectorItem
{
public:
NewDocItem( QListView *parent, const DocLnk &f )
: FileSelectorItem( parent, f ) {
setText( 0, QObject::tr("New Document") );
QImage img( Resource::loadImage( "new" ) );
QPixmap pm;
pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
setPixmap( 0, pm );
}
QString key ( int, bool ) const {
return QString("\n");
}
void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {
QFont oldFont = p->font();
QFont newFont = p->font();
newFont.setWeight( QFont::Bold );
p->setFont( newFont );
FileSelectorItem::paintCell( p, cg, column, width, alignment );
p->setFont( oldFont );
}
int width( const QFontMetrics &fm, const QListView *v, int c ) const {
return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font
}
};
//===========================================================================
class FileSelectorPrivate
{
public:
TypeCombo *typeCombo;
CategorySelect *catSelect;
QValueList<QRegExp> mimeFilters;
int catId;
bool showNew;
NewDocItem *newDocItem;
DocLnkSet files;
QHBox *toolbar;
};
/*!
\class FileSelector fileselector.h
\brief The FileSelector widget allows the user to select DocLnk objects.
This class presents a file selection dialog to the user. This widget
is usually the first widget seen in a \link docwidget.html
document-oriented application\endlink. The developer will most often
create this widget in combination with a <a
href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate
editor and/or viewer widget for their application. This widget
should be shown first and the user can the select which document
they wish to operate on. Please refer to the implementation of
texteditor for an example of how to tie these classes together.
Use setNewVisible() depending on whether the application can be used
to create new files or not. Use setCloseVisible() depending on
whether the user may leave the dialog without creating or selecting
a document or not. The number of files in the view is available from
fileCount(). To force the view to be updated call reread().
If the user presses the 'New Document' button the newSelected()
signal is emitted. If the user selects an existing file the
fileSelected() signal is emitted. The selected file's \link
doclnk.html DocLnk\endlink is available from the selected()
function. If the file selector is no longer necessary the closeMe()
signal is emitted.
\ingroup qtopiaemb
\sa FileManager
*/
/*!
Constructs a FileSelector with mime filter \a f.
The standard Qt \a parent and \a name parameters are passed to the
parent widget.
If \a newVisible is TRUE, the widget has a button to allow the user
the create "new" documents; this is useful for applications that can
create and edit documents but not suitable for applications that
only provide viewing.
\a closeVisible is deprecated
\sa DocLnkSet::DocLnkSet()
*/
FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )
: QVBox( parent, name ), filter( f )
{
setMargin( 0 );
setSpacing( 0 );
d = new FileSelectorPrivate();
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index 2b5e0d2..147134c 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,232 +1,230 @@
/**********************************************************************
** 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 <qpe/qpeapplication.h>
#include "fontfactoryinterface.h"
#include "fontdatabase.h"
#include <qpe/qlibrary.h>
-#ifdef QWS
#include <qfontmanager_qws.h>
-#endif
#include <qdir.h>
#include <qdict.h>
#include <stdio.h>
#include <stdlib.h>
static QString fontDir()
{
QString qtdir = getenv("QTDIR");
if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
return qtdir+"/lib/fonts/";
}
#ifdef QT_NO_FONTDATABASE
static QString fontFamily( const QString& key )
{
int u0 = key.find('_');
int u1 = key.find('_',u0+1);
int u2 = key.find('_',u1+1);
QString family = key.left(u0);
//int pointSize = key.mid(u0+1,u1-u0-1).toInt();
//int weight = key.mid(u1+1,u2-u1-1).toInt();
//bool italic = key.mid(u2-1,1) == "i";
// #### ignores _t and _I fields
return family;
}
#endif
QValueList<FontFactory> *FontDatabase::factoryList = 0;
/*!
\class FontDatabase fontdatabase.h
\brief The FontDatabase class provides information about available fonts.
Most often you will simply want to query the database for the
available font families().
Use FontDatabase rather than QFontDatabase when you may need access
to fonts that are not normally available. For example, if the
freetype library and the Qtopia freetype plugin are installed,
TrueType fonts will be available to your application. Font renderer
plugins have greater resource requirements than system fonts so they
should be used only when necessary. You can force the loading of
font renderer plugins with loadRenderers().
\ingroup qtopiaemb
*/
/*!
Constructs a FontDatabase object.
*/
FontDatabase::FontDatabase()
#ifndef QT_NO_FONTDATABASE
: QFontDatabase()
#endif
{
if ( !factoryList )
loadRenderers();
}
/*!
Returns a list of names of all the available font families.
*/
QStringList FontDatabase::families() const
{
#ifndef QT_NO_FONTDATABASE
return QFontDatabase::families();
#else
QStringList list;
QDict<void> familyDict;
QDiskFont *qdf;
for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
qdf=qt_fontmanager->diskfonts.next()) {
QString familyname = qdf->name;
if ( !familyDict.find( familyname ) ) {
familyDict.insert( familyname, (void *)1 );
list.append( familyname );
}
}
QDir dir(fontDir(),"*.qpf");
for (int i=0; i<(int)dir.count(); i++) {
QString familyname = fontFamily(dir[i]);
if ( !familyDict.find( familyname ) ) {
familyDict.insert( familyname, (void *)1 );
list.append( familyname );
}
}
return list;
#endif
}
#ifdef QT_NO_FONTDATABASE
/*!
Returns a list of standard fontsizes.
*/
QValueList<int> FontDatabase::standardSizes()
{
static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
36, 48, 72, 0 };
static bool first = TRUE;
static QValueList<int> sList;
if ( first ) {
first = FALSE;
int i = 0;
while( s[i] )
sList.append( s[i++] );
}
return sList;
}
#endif
/*!
Load any font renderer plugins that are available and make the fonts
that the plugins can read available.
*/
void FontDatabase::loadRenderers()
{
#ifndef QT_NO_COMPONENT
if ( !factoryList )
factoryList = new QValueList<FontFactory>;
QValueList<FontFactory>::Iterator mit;
for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
qt_fontmanager->factories.setAutoDelete( false );
qt_fontmanager->factories.removeRef( (*mit).factory );
qt_fontmanager->factories.setAutoDelete( true );
(*mit).interface->release();
(*mit).library->unload();
delete (*mit).library;
}
factoryList->clear();
QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
QDir dir( path, "lib*.so" );
QStringList list = dir.entryList();
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
FontFactoryInterface *iface = 0;
QLibrary *lib = new QLibrary( path + "/" + *it );
if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
FontFactory factory;
factory.library = lib;
factory.interface = iface;
factory.factory = factory.interface->fontFactory();
factoryList->append( factory );
qt_fontmanager->factories.append( factory.factory );
readFonts( factory.factory );
} else {
delete lib;
}
}
#endif
}
/*!
\internal
*/
void FontDatabase::readFonts( QFontFactory *factory )
{
// Load in font definition file
QString fn = fontDir() + "fontdir";
FILE* fontdef=fopen(fn.local8Bit(),"r");
if(!fontdef) {
QCString temp=fn.local8Bit();
qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
temp.data());
return;
}
char buf[200]="";
char name[200]="";
char render[200]="";
char file[200]="";
char flags[200]="";
char isitalic[10]="";
fgets(buf,200,fontdef);
while(!feof(fontdef)) {
if ( buf[0] != '#' ) {
int weight=50;
int size=0;
flags[0]=0;
sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
QString filename;
if ( file[0] != '/' )
filename = fontDir();
filename += file;
if ( QFile::exists(filename) ) {
if( factory->name() == render ) {
QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
weight,size,flags,filename);
qt_fontmanager->diskfonts.append(qdf);
#if QT_VERSION >= 232
QFontDatabase::qwsAddDiskFont( qdf );
#endif
}
}
}
fgets(buf,200,fontdef);
}
fclose(fontdef);
}
diff --git a/library/fontmanager.cpp b/library/fontmanager.cpp
index 28a5212..c854133 100644
--- a/library/fontmanager.cpp
+++ b/library/fontmanager.cpp
@@ -1,103 +1,101 @@
/**********************************************************************
** 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.
**
**********************************************************************/
-#ifdef QWS
#include "fontmanager.h"
#include <qfile.h>
#include <stdlib.h>
#include <qgfx_qws.h>
/*
QFontInfo doesn't work in QWS at the moment,
otherwise we would just have used that to check
the real values
For now, there are only two Unicode fonts in
the known universe...
*/
bool FontManager::hasUnicodeFont()
{
QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
QString suffix;
if ( qt_screen->isTransformed() ) {
suffix += "_t";
QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
}
suffix += ".qpf";
return QFile::exists( fontDir+"cyberbit_120_50"+suffix )
|| QFile::exists( fontDir+"unifont_160_50"+suffix ) ||
QFile::exists( fontDir+"arial_140_50" + suffix );
}
QFont FontManager::unicodeFont( Spacing sp )
{
QString key;
QString fontName;
QString fontDir = getenv("QTDIR") + QString("/lib/fonts/");
int size;
if ( sp == Proportional ) {
fontName = "Arial";
size=14;
key = "arial_140_50";
} else {
fontName = "Unifont";
size=16;
key = "unifont_160_50";
}
QString suffix;
if ( qt_screen->isTransformed() ) {
suffix += "_t";
QPoint a = qt_screen->mapToDevice(QPoint(0,0),QSize(2,2));
QPoint b = qt_screen->mapToDevice(QPoint(1,1),QSize(2,2));
suffix += QString::number( a.x()*8+a.y()*4+(1-b.x())*2+(1-b.y()) );
}
suffix += ".qpf";
// if we cannot find it, try the other one
if ( !QFile::exists(fontDir+key+suffix) ) {
key = (sp == Fixed ) ? "arial_140_50" : "unifont_160_50";
if ( QFile::exists(fontDir+key+suffix) ) {
fontName = (sp == Fixed) ? "Arial" : "Unifont";
size = (sp == Fixed) ? 14 : 16;
} else {
key = "cyberbit_120_50";
if ( QFile::exists(fontDir+key+suffix) ) {
fontName = "Cyberbit";
size = 12;
} else {
fontName = "Helvetica";
size = 14;
}
}
}
return QFont(fontName,size);
}
-#endif
diff --git a/library/global.cpp b/library/global.cpp
index 9b908bf..d02e711 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,812 +1,806 @@
/**********************************************************************
** 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>
-#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
-#include "qpe/qcopenvelope_qws.h"
-#endif
+#include <qpe/qcopenvelope_qws.h>
#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 <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();
QStringList list = QStringList::split('\n', QString( array ) );
for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
if( (*it).startsWith("autocheck = 0" ) ){
return false;
}else if( (*it).startsWith("autocheck = 1" ) ){
return true;
}
}
return true;
}
}
//#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 )
{
-#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
}
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 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");
}
/*!
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(Q_WS_QWS) && !defined(QT_NO_COP)
+#if!defined(QT_NO_COP)
QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
e << message;
#endif
}
/*!
\internal
*/
void Global::applyStyle()
{
-#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
+#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(Q_WS_QWS) && !defined(QT_NO_COP)
+#if !defined(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)
+#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(Q_WS_QWS) && !defined(QT_NO_COP)
+#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(Q_WS_QWS) && !defined(QT_NO_COP)
+#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(Q_WS_QWS) && !defined(QT_NO_COP)
+#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 ) ) {
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(Q_WS_QWS) && !defined(QT_NO_COP)
+#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
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
qDebug("libfile = %s", libexe.latin1() );
if ( QFile::exists( libexe ) ) {
qDebug("calling quickexec %s", libexe.latin1() );
quickexecv( libexe.utf8().data(), (const char **)args );
} else
#endif
{
if ( !::vfork() ) {
for ( int fd = 3; fd < 100; fd++ )
::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 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 )
{
if ( qApp->type() != QApplication::GuiServer ) {
// ask the server to do the work
-#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
+#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;
}
// Attempt to execute the app using a builtin class for the app first
// else try and find it in the bin directory
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)
+#if !defined(QT_NO_COP)
QString ap=list[0];
qDebug("executing %s", ap.latin1() );
/* if need be, sending a qcop message will result in an invoke, see
preceeding function */
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 '\', '"', 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();
if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
continue;
DocLnkSet ide( path, 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()
{
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;
}
#include "global.moc"
diff --git a/library/ir.cpp b/library/ir.cpp
index a7cf7b1..b5b726d 100644
--- a/library/ir.cpp
+++ b/library/ir.cpp
@@ -1,120 +1,118 @@
/**********************************************************************
** 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 "ir.h"
#include <qstring.h>
-#ifdef QWS
#include "qcopenvelope_qws.h"
#include <qcopchannel_qws.h>
-#endif
#include "applnk.h"
/*!
\class Ir ir.h
\brief The Ir class implements basic support for sending objects over an
infrared communication link.
Both \link doclnk.html DocLnk\endlink objects and files can be
sent to another device via the infrared link using the send()
function. When the send has completed the done() signal is
emitted.
The supported() function returns whether the device supports
infrared communication or not.
\ingroup qtopiaemb
*/
/*!
Constructs an Ir object. The \a parent and \a name classes are the
standard QObject parameters.
*/
Ir::Ir( QObject *parent, const char *name )
: QObject( parent, name )
{
#ifndef QT_NO_COP
ch = new QCopChannel( "QPE/Obex" );
connect( ch, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(obexMessage( const QCString &, const QByteArray &)) );
#endif
}
/*!
Returns TRUE if the system supports infrared communication;
otherwise returns FALSE.
*/
bool Ir::supported()
{
#ifndef QT_NO_COP
return QCopChannel::isRegistered( "QPE/Obex" );
#endif
}
/*!
Sends the object in file \a fn over the infrared link. The \a
description is used in the text shown to the user while sending
is in progress. The optional \a mimetype parameter specifies the
mimetype of the object. If this parameter is not set, it is
determined by the the filename's suffix.
\sa done()
*/
void Ir::send( const QString &fn, const QString &description, const QString &mimetype)
{
if ( !filename.isEmpty() ) return;
filename = fn;
#ifndef QT_NO_COP
QCopEnvelope e("QPE/Obex", "send(QString,QString,QString)");
e << description << filename << mimetype;
#endif
}
/*!
\overload
Uses the DocLnk::file() and DocLnk::type() of \a doc.
\sa done()
*/
void Ir::send( const DocLnk &doc, const QString &description )
{
send( doc.file(), description, doc.type() );
}
/*!
\fn Ir::done( Ir *ir );
This signal is emitted by \a ir, when the send comand has been processed.
*/
/*!\internal
*/
void Ir::obexMessage( const QCString &msg, const QByteArray &data)
{
if ( msg == "done(QString)" ) {
QString fn;
QDataStream stream( data, IO_ReadOnly );
stream >> fn;
if ( fn == filename )
emit done( this );
}
}
diff --git a/library/lnkproperties.cpp b/library/lnkproperties.cpp
index 0b50bae..50cf5af 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -1,291 +1,289 @@
/**********************************************************************
** 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.
**
**********************************************************************/
// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
// have this class.
#define QTOPIA_INTERNAL_FSLP
#include "lnkproperties.h"
#include "lnkproperties.h"
#include "lnkpropertiesbase_p.h"
#include "ir.h"
#include <qpe/qpeapplication.h>
#include <qpe/applnk.h>
#include <qpe/global.h>
#include <qpe/categorywidget.h>
-#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
-#endif
#include <qpe/filemanager.h>
#include <qpe/config.h>
#include <qpe/storage.h>
#include <qpe/qpemessagebox.h>
#include <qpe/mimetype.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 <qfileinfo.h>
#include <qmessagebox.h>
#include <qsize.h>
#include <qcombobox.h>
#include <qregexp.h>
#include <qbuttongroup.h>
#include <stdlib.h>
LnkProperties::LnkProperties( AppLnk* l, QWidget* parent )
: QDialog( parent, 0, TRUE ), lnk(l), fileSize( 0 )
{
setCaption( tr("Properties") );
QVBoxLayout *vbox = new QVBoxLayout( this );
d = new LnkPropertiesBase( this );
vbox->add( d );
d->docname->setText(l->name());
QString inf;
if ( l->type().isEmpty() ) {
d->type->hide();
d->typeLabel->hide();
} else {
d->type->setText( l->type() );
}
if ( l->comment().isEmpty() ) {
d->comment->hide();
d->commentLabel->hide();
} else {
d->comment->setText( l->comment() );
}
connect(d->beam,SIGNAL(clicked()),this,SLOT(beamLnk()));
if ( lnk->type().contains('/') ) { // A document? (#### better predicate needed)
connect(d->unlink,SIGNAL(clicked()),this,SLOT(unlinkLnk()));
connect(d->duplicate,SIGNAL(clicked()),this,SLOT(duplicateLnk()));
d->docname->setReadOnly( FALSE );
d->preload->hide();
d->rotate->hide();
d->rotateButtons->hide();
d->labelspacer->hide();
// ### THIS MUST GO, FIX WIERD BUG in QLAYOUT
d->categoryEdit->kludge();
d->categoryEdit->setCategories( lnk->categories(),
"Document View",
tr("Document View") );
setupLocations();
} else {
d->unlink->hide();
d->duplicate->hide();
d->beam->hide();
d->hline->hide();
d->locationLabel->hide();
d->locationCombo->hide();
// Can't edit categories, since the app .desktop files are global,
// possibly read-only.
d->categoryEdit->hide();
d->docname->setReadOnly( TRUE );
if ( l->property("CanFastload") == "0" )
d->preload->hide();
if ( !l->property("Rotation"). isEmpty ()) {
d->rotate->setChecked ( true );
d->rotateButtons->setButton((l->rotation().toInt()%360)/90);
}
else {
d->rotateButtons->setEnabled(false);
}
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps",',');
d->preload->setChecked( apps.contains(l->exec()) );
if ( Global::isBuiltinCommand(lnk->exec()) )
d->preload->hide(); // builtins are always fast
currentLocation = 0; // apps not movable (yet)
}
}
LnkProperties::~LnkProperties()
{
}
void LnkProperties::unlinkLnk()
{
if ( QPEMessageBox::confirmDelete( this, tr("Delete"), lnk->name() ) ) {
lnk->removeFiles();
if ( QFile::exists(lnk->file()) ) {
QMessageBox::warning( this, tr("Delete"), tr("File deletion failed.") );
} else {
reject();
}
}
}
void LnkProperties::setupLocations()
{
QFileInfo fi( lnk->file() );
fileSize = fi.size();
StorageInfo storage;
const QList<FileSystem> &fs = storage.fileSystems();
QListIterator<FileSystem> it ( fs );
QString s;
QString homeDir = getenv("HOME");
QString hardDiskHome;
QString hardDiskPath;
int index = 0;
currentLocation = -1;
for ( ; it.current(); ++it ) {
// we add 10k to the file size so we are sure we can also save the desktop file
if ( (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize() > (ulong)fileSize + 10000 ) {
if ( (*it)->isRemovable() ||
(*it)->disk() == "/dev/mtdblock1" ||
(*it)->disk() == "/dev/mtdblock/1" ||
(*it)->disk().left(13) == "/dev/mtdblock" ||
(*it)->disk() == "/dev/mtdblock6" ||
(*it)->disk() == "tmpfs" ) {
d->locationCombo->insertItem( (*it)->name(), index );
locations.append( ( ((*it)->isRemovable() ||
(*it)->disk() == "/dev/mtdblock6" ||
(*it)->disk() == "tmpfs" )
? (*it)->path() : homeDir) );
if ( lnk->file().contains( (*it)->path() ) ) {
d->locationCombo->setCurrentItem( index );
currentLocation = index;
}
index++;
} else if ( (*it)->name().contains( tr("Hard Disk") ) &&
homeDir.contains( (*it)->path() ) &&
(*it)->path().length() > hardDiskHome.length() ) {
hardDiskHome = (*it)->name();
hardDiskPath = (*it)->path();
}
}
}
if ( !hardDiskHome.isEmpty() ) {
d->locationCombo->insertItem( hardDiskHome );
locations.append( hardDiskPath );
if ( currentLocation == -1 ) { // assume it's the hard disk
d->locationCombo->setCurrentItem( index );
currentLocation = index;
}
}
}
void LnkProperties::duplicateLnk()
{
// The duplicate takes the new properties.
DocLnk newdoc( *((DocLnk *)lnk) );
if ( d->docname->text() == lnk->name() )
newdoc.setName(tr("Copy of ")+d->docname->text());
else
newdoc.setName(d->docname->text());
if ( !copyFile( newdoc ) ) {
QMessageBox::warning( this, tr("Duplicate"), tr("File copy failed.") );
return;
}
reject();
}
bool LnkProperties::moveLnk()
{
DocLnk newdoc( *((DocLnk *)lnk) );
newdoc.setName(d->docname->text());
if ( !copyFile( newdoc ) ) {
QMessageBox::warning( this, tr("Details"), tr("Moving Document failed.") );
return FALSE;
}
// remove old lnk
lnk->removeFiles();
return TRUE;
}
void LnkProperties::beamLnk()
{
Ir ir;
DocLnk doc( *((DocLnk *)lnk) );
doc.setName(d->docname->text());
reject();
ir.send( doc, doc.comment() );
}
bool LnkProperties::copyFile( DocLnk &newdoc )
{
const char *linkExtn = ".desktop";
QString fileExtn;
int extnPos = lnk->file().findRev( '.' );
if ( extnPos > 0 )
fileExtn = lnk->file().mid( extnPos );
QString safename = newdoc.name();
safename.replace(QRegExp("/"),"_");
QString fn = locations[ d->locationCombo->currentItem() ]
+ "/Documents/" + newdoc.type() + "/" + safename;
if ( QFile::exists(fn + fileExtn) || QFile::exists(fn + linkExtn) ) {
int n=1;
QString nn = fn + "_" + QString::number(n);
while ( QFile::exists(nn+fileExtn) || QFile::exists(nn+linkExtn) ) {
n++;
nn = fn + "_" + QString::number(n);
}
fn = nn;
}
newdoc.setFile( fn + fileExtn );
newdoc.setLinkFile( fn + linkExtn );
// Copy file
FileManager fm;
if ( !fm.copyFile( *lnk, newdoc ) )
return FALSE;
return TRUE;
}
void LnkProperties::done(int ok)
{
if ( ok ) {
bool changed=FALSE;
bool reloadMime=FALSE;
if ( lnk->name() != d->docname->text() ) {
lnk->setName(d->docname->text());
changed=TRUE;
}
if ( d->categoryEdit->isVisible() ) {
QArray<int> tmp = d->categoryEdit->newCategories();
if ( lnk->categories() != tmp ) {
lnk->setCategories( tmp );
changed = TRUE;
}
}
diff --git a/library/network.cpp b/library/network.cpp
index 185b147..3568809 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,286 +1,284 @@
/**********************************************************************
** 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/network.h"
#include "qpe/networkinterface.h"
#include "qpe/global.h"
#include "qpe/config.h"
#include "qpe/resource.h"
#include "qpe/qpeapplication.h"
-#ifdef QWS
#include <qpe/qcopenvelope_qws.h>
-#endif
#include <qpe/qlibrary.h>
#include <qlistbox.h>
#include <qdir.h>
#include <qlayout.h>
#include <qdict.h>
#include <qtranslator.h>
#include <stdlib.h>
#ifndef QT_NO_COP
class NetworkEmitter : public QCopChannel {
Q_OBJECT
public:
NetworkEmitter() : QCopChannel("QPE/Network",qApp)
{
}
void receive(const QCString &msg, const QByteArray&)
{
if ( msg == "choicesChanged()" )
emit changed();
}
signals:
void changed();
};
/*!
\internal
Requests that the service \a choice be started. The \a password is
the password to use if required.
*/
void Network::start(const QString& choice, const QString& password)
{
QCopEnvelope e("QPE/Network", "start(QString,QString)");
e << choice << password;
}
/*!
\class Network network.h
\brief The Network class provides network access functionality.
\internal
*/
// copy the proxy settings of the active config over to the Proxies.conf file
/*!
\internal
*/
void Network::writeProxySettings( Config &cfg )
{
Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
proxy.setGroup("Properties");
cfg.setGroup("Proxy");
proxy.writeEntry("type", cfg.readEntry("type") );
proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
proxy.writeEntry("httphost", cfg.readEntry("httphost") );
proxy.writeEntry("httpport", cfg.readEntry("httpport") );
proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
cfg.setGroup("Properties");
}
/*!
\internal
Stops the current network service.
*/
void Network::stop()
{
QCopEnvelope e("QPE/Network", "stop()");
}
static NetworkEmitter *emitter = 0;
/*!
\internal
*/
void Network::connectChoiceChange(QObject* receiver, const char* slot)
{
if ( !emitter )
emitter = new NetworkEmitter;
QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
}
#endif // QT_NO_COP
/*!
\internal
*/
QString Network::settingsDir()
{
return Global::applicationFileName("Network", "modules");
}
#ifndef QT_NO_COP
/*!
\internal
*/
QStringList Network::choices(QListBox* lb, const QString& dir)
{
QStringList list;
if ( lb )
lb->clear();
QString adir = dir.isEmpty() ? settingsDir() : dir;
QDir settingsdir(adir);
settingsdir.mkdir(adir);
QStringList files = settingsdir.entryList("*.conf");
for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
QString filename = settingsdir.filePath(*it);
Config cfg(filename, Config::File);
cfg.setGroup("Info");
if ( lb )
lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
cfg.readEntry("Name"));
list.append(filename);
}
return list;
}
class NetworkServer : public QCopChannel {
Q_OBJECT
public:
NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
{
up = FALSE;
examineNetworks( TRUE );
QCopChannel* card = new QCopChannel("QPE/Card",parent);
connect(card,SIGNAL(received(const QCString &, const QByteArray&)),
this,SLOT(cardMessage(const QCString &, const QByteArray&)));
}
~NetworkServer()
{
stop();
}
bool networkOnline() const
{
return up;
}
private:
void receive(const QCString &msg, const QByteArray& data)
{
if ( msg == "start(QString,QString)" ) {
QDataStream stream(data,IO_ReadOnly);
QString file,password;
stream >> file >> password;
if ( file.isEmpty() ) {
QStringList l = Network::choices();
for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
Config cfg(*i,Config::File);
cfg.setGroup("Info");
QString type = cfg.readEntry("Type");
NetworkInterface* plugin = Network::loadPlugin(type);
cfg.setGroup("Properties");
if ( plugin && plugin->isAvailable(cfg) ) {
file = *i;
break;
}
}
if ( file.isEmpty() ) {
QCopEnvelope("QPE/Network", "failed()");
return;
}
}
start(file,password);
} else if ( msg == "stop()" ) {
stop();
} else if ( msg == "choicesChanged()" ) {
examineNetworks();
}
}
private slots:
void cardMessage(const QCString &msg, const QByteArray&)
{
if ( msg == "stabChanged()" )
examineNetworks();
}
private:
void examineNetworks( bool firstStart = FALSE )
{
QStringList l = Network::choices();
bool wasup = up; up=FALSE;
QStringList pavailable = available;
available.clear();
for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
Config cfg(*it,Config::File);
cfg.setGroup("Info");
QString type = cfg.readEntry("Type");
NetworkInterface* plugin = Network::loadPlugin(type);
cfg.setGroup("Properties");
if ( plugin ) {
if ( plugin->isActive(cfg) ) {
up = TRUE;
if ( firstStart )
plugin->start( cfg );
}
if ( plugin->isAvailable(cfg) )
available.append(*it);
}
}
// Try to work around unreproducible bug whereby
// the netmon applet shows wrong state.
bool reannounce = wait<0;
if ( available != pavailable || reannounce ) {
QCopEnvelope e("QPE/Network", "available(QStringList)");
e << available;
}
if ( up != wasup || reannounce ) {
QCopEnvelope("QPE/Network", up ? "up()" : "down()");
}
}
void start( const QString& file, const QString& password )
{
if ( !current.isEmpty() )
stop();
current = QString::null;
Config cfg(file, Config::File);
cfg.setGroup("Info");
QString type = cfg.readEntry("Type");
NetworkInterface* plugin = Network::loadPlugin(type);
bool started = FALSE;
if ( plugin ) {
cfg.setGroup("Properties");
if ( plugin->start(cfg,password) ) {
Network::writeProxySettings( cfg );
current = file;
wait=0;
startTimer(400);
started = TRUE;
}
}
if ( !started ) {
QCopEnvelope("QPE/Network", "failed()");
}
}
void stop()
{
bool stopped = FALSE;
if ( !current.isEmpty() ) {
Config cfg(current, Config::File);
diff --git a/library/networkinterface.cpp b/library/networkinterface.cpp
index 2b5c77e..0ba773a 100644
--- a/library/networkinterface.cpp
+++ b/library/networkinterface.cpp
@@ -1,106 +1,104 @@
/**********************************************************************
** 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 "networkinterface.h"
#include "network.h"
#include "config.h"
#include <stdio.h>
QString NetworkInterface::device( Config& cfg ) const
{
return cfg.readEntry("Device");
}
bool NetworkInterface::isActive( Config& cfg ) const
{
QString dev = device(cfg);
if ( dev.isEmpty() )
return FALSE;
QString dev0 = dev+'0';
FILE* f;
f = fopen("/proc/net/dev", "r");
if ( f ) {
char line[1024];
char devname[80];
while ( fgets( line, 1024, f ) ) {
if ( sscanf(line," %[^:]:", devname)==1 )
{
if ( devname == dev || devname == dev0 ) {
fclose(f);
-#ifdef QWS
Network::writeProxySettings( cfg );
-#endif
return TRUE;
}
}
}
fclose(f);
}
return FALSE;
}
QString NetworkInterface::cardType( Config& cfg ) const
{
return cfg.readEntry("CardType");
}
bool NetworkInterface::isAvailable( Config& cfg ) const
{
QString ct = cardType(cfg);
if ( ct.isEmpty() )
return FALSE;
FILE* f = fopen("/var/run/stab", "r");
if (!f) f = fopen("/var/state/pcmcia/stab", "r");
if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
if ( f ) {
char line[1024];
char devtype[80];
while ( fgets( line, 1024, f ) ) {
if ( sscanf(line,"%*d %s %*s", devtype )==1 )
{
if ( ct == devtype ) {
fclose(f);
return TRUE;
}
}
}
fclose(f);
}
return FALSE;
}
bool NetworkInterface::start( Config& cfg, const QString& /*password*/ )
{
return start(cfg);
}
bool NetworkInterface::needPassword( Config& ) const
{
return FALSE;
}
QWidget* NetworkInterface::addStateWidget( QWidget*, Config& ) const
{
return 0;
}
diff --git a/library/password.cpp b/library/password.cpp
index 41b3358..4b22b65 100644
--- a/library/password.cpp
+++ b/library/password.cpp
@@ -1,288 +1,286 @@
/**********************************************************************
** 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 "password.h"
#include "config.h"
#include "global.h"
#include "backend/contact.h"
#include <qlabel.h>
#include <qlineedit.h>
#include <qtextview.h>
#include <qstring.h>
#include <qapplication.h>
#include <qfile.h>
-#ifdef QWS
#include <qwindowsystem_qws.h>
-#endif
#include <qdialog.h>
#include <unistd.h> //for sleep
#include "passwordbase_p.h"
class PasswordDialog : public PasswordBase
{
Q_OBJECT
public:
PasswordDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~PasswordDialog();
void clear();
void setPrompt( const QString& );
signals:
void passwordEntered( const QString& );
protected:
bool eventFilter( QObject*, QEvent* );
void keyPressEvent( QKeyEvent * );
private:
void input( QString );
friend class Password;
QString text;
};
extern "C" char *crypt(const char *key, const char *salt);
static QString qcrypt(const QString& k, const char *salt)
{
return QString::fromUtf8(crypt(k.utf8(),salt));
}
/*
* Constructs a PasswordDialog which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
PasswordDialog::PasswordDialog( QWidget* parent, const char* name, WFlags fl )
: PasswordBase( parent, name, fl )
{
QRect desk = qApp->desktop()->geometry();
if ( desk.width() < 220 ) {
QFont f( font() );
f.setPointSize( 18 );
setFont( f );
f.setPointSize( 12 );
prompt->setFont( f );
}
button_0->installEventFilter( this );
button_1->installEventFilter( this );
button_2->installEventFilter( this );
button_3->installEventFilter( this );
button_4->installEventFilter( this );
button_5->installEventFilter( this );
button_6->installEventFilter( this );
button_7->installEventFilter( this );
button_8->installEventFilter( this );
button_9->installEventFilter( this );
button_OK->installEventFilter( this );
setFocus();
}
/*
* Destroys the object and frees any allocated resources
*/
PasswordDialog::~PasswordDialog()
{
// no need to delete child widgets, Qt does it all for us
}
/*!
\reimp
*/
bool PasswordDialog::eventFilter( QObject*o, QEvent*e )
{
if ( e->type() == QEvent::MouseButtonRelease ) {
if ( o == button_OK ) {
emit passwordEntered( text );
} else {
QLabel *l = (QLabel*)o;
input(l->text());
}
}
return FALSE;
}
/*!
\reimp
*/
void PasswordDialog::keyPressEvent( QKeyEvent * )
{
#if 0
if ( e->key() == Key_Enter || e->key() == Key_Return )
emit passwordEntered( text );
else
input( e->text() );
#endif
}
/*!
*/
void PasswordDialog::input( QString c )
{
text += c;
display->setText( text );
}
/*!
*/
void PasswordDialog::setPrompt( const QString& s )
{
prompt->setText( s );
}
void PasswordDialog::clear()
{
text = "";
input("");
}
class PasswdDlg : public QDialog
{
public:
PasswdDlg( QWidget *parent, const char * name, bool modal, bool fullscreen = FALSE )
: QDialog( parent, name, modal, fullscreen ? WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ),
modl(modal)
{
passw = new PasswordDialog( this );
if ( fullscreen ) {
QRect desk = qApp->desktop()->geometry();
setGeometry( 0, 0, desk.width(), desk.height() );
}
connect( passw, SIGNAL(passwordEntered(const QString&)),
this, SLOT(accept()) );
}
void resizeEvent( QResizeEvent * )
{
passw->resize( size() );
}
void reset()
{
passw->clear();
}
void execNonModal()
{
if ( !modl ) {
reset();
showFullScreen();
do {
qApp->enter_loop();
} while (result()!=1);
}
}
void accept()
{
if ( !modl )
qApp->exit_loop();
QDialog::accept();
}
PasswordDialog *passw;
bool modl;
};
class OwnerDlg : public QDialog
{
public:
OwnerDlg( QWidget *parent, const char * name, Contact c,
bool modal, bool fullscreen = FALSE )
: QDialog( parent, name, modal,
fullscreen ?
WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
{
if ( fullscreen ) {
QRect desk = qApp->desktop()->geometry();
setGeometry( 0, 0, desk.width(), desk.height() );
}
// set up contents.
QString text = "<H1>" + tr("Owner Information") + "</H1>";
text += c.toRichText();
tv = new QTextView(this);
tv->setText(text);
tv->viewport()->installEventFilter(this);
}
void resizeEvent( QResizeEvent * )
{
tv->resize( size() );
}
bool eventFilter(QObject *o, QEvent *e)
{
if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
accept();
return TRUE;
}
return QWidget::eventFilter(o, e);
}
void mousePressEvent( QMouseEvent * ) { accept(); }
private:
QTextView *tv;
};
/*!
Returns a crypted password entered by the user when prompted with \a prompt
The returned value is QString::null if the user cancels the operation,
or the empty string if the user enters no password (but confirms the
dialog).
*/
QString Password::getPassword( const QString& prompt )
{
PasswdDlg pd(0,0,TRUE);
pd.passw->setPrompt( prompt );
pd.showMaximized();
int r = pd.exec();
if ( r == QDialog::Accepted ) {
if (pd.passw->text.isEmpty())
return "";
else
return qcrypt(pd.passw->text,"a0");
} else {
return QString::null;
}
}
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index 214c721..9cbe92b 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,276 +1,275 @@
/**********************************************************************
** 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.
**
**********************************************************************/
-#ifdef QWS
#define QTOPIA_INTERNAL_LANGLIST
#include <qapplication.h>
#include <qstyle.h>
#include <qwidget.h>
#include <qpainter.h>
#include <qtimer.h>
#include <qwhatsthis.h>
#include "qcopenvelope_qws.h"
#include "qpedecoration_qws.h"
#include <qdialog.h>
#include <qdrawutil.h>
#include <qgfx_qws.h>
#include "qpeapplication.h"
#include "resource.h"
#include "global.h"
#include "qlibrary.h"
#include "windowdecorationinterface.h"
#include <qfile.h>
#include <qsignal.h>
#include <stdlib.h>
extern QRect qt_maxWindowRect;
#define WHATSTHIS_MODE
#ifndef QT_NO_QWS_QPE_WM_STYLE
#ifndef QT_NO_IMAGEIO_XPM
/* XPM */
static const char * const qpe_close_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
" ",
" ",
" ..... ",
" ..+++++.. ",
" .+++++++++. ",
" .+..+++..+. ",
" .++...+...++. ",
" .+++.....+++. ",
" .++++...++++. ",
" .+++.....+++. ",
" .++...+...++. ",
" .+..+++..+. ",
" .+++++++++. ",
" ..+++++.. ",
" ..... ",
" "};
/* XPM */
static const char * const qpe_accept_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
" ",
" ",
" ..... ",
" ..+++++.. ",
" .+++++++++. ",
" .+++++++++. ",
" .+++++++..++. ",
" .++.+++...++. ",
" .+...+...+++. ",
" .+......++++. ",
" .++....+++++. ",
" .++..+++++. ",
" .+++++++++. ",
" ..+++++.. ",
" ..... ",
" "};
#endif // QT_NO_IMAGEIO_XPM
class HackWidget : public QWidget
{
public:
bool needsOk() {
return (getWState() & WState_Reserved1 ) ||
(inherits( "QDialog" ) && !inherits( "QMessageBox" ) );
}
};
static QImage scaleButton( const QImage &img, int height )
{
if ( img.height() != 0 && img.height() != height ) {
return img.smoothScale( img.width()*height/img.height(), height );
} else {
return img;
}
}
class TLWidget : public QWidget
{
public:
QWSManager *manager()
{
return topData()->qwsManager;
}
QTLWExtra *topExtra()
{
return topData();
}
void setWState( uint s ) { QWidget::setWState( s ); }
void clearWState( uint s ) { QWidget::clearWState( s ); }
};
QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
: QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
{
wtTimer = new QTimer( this );
connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
}
void QPEManager::updateActive()
{
QWidget *newActive = qApp->activeWindow();
if ( newActive && (QWidget*)active == newActive )
return;
if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
}
if ( newActive && ((TLWidget *)newActive)->manager() ) {
active = newActive;
((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
} else if ( !newActive ) {
active = 0;
}
}
int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
{
QRect rect(w->geometry());
if ( decoration->region( w, rect,
(QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
return QPEDecoration::Help;
for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
return (QWSDecoration::Region)i;
}
return QWSDecoration::None;
}
bool QPEManager::eventFilter( QObject *o, QEvent *e )
{
QWSManager *mgr = (QWSManager *)o;
QWidget *w = mgr->widget();
switch ( e->type() ) {
case QEvent::MouseButtonPress:
{
pressTime = QTime::currentTime();
QPoint p = ((QMouseEvent*)e)->globalPos();
int inRegion = pointInQpeRegion( w, p );
#ifdef WHATSTHIS_MODE
if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
QString text;
switch ( inRegion ) {
case QWSDecoration::Close:
if ( ((HackWidget*)w)->needsOk() )
text = tr("Click to close this window, discarding changes.");
else
text = tr("Click to close this window.");
break;
case QWSDecoration::Minimize:
text = tr("Click to close this window and apply changes.");
break;
case QWSDecoration::Maximize:
if ( w->isMaximized() )
text = tr("Click to make this window moveable.");
else
text = tr("Click to make this window use all available screen area.");
break;
default:
break;
}
QWhatsThis::leaveWhatsThisMode( text );
whatsThisTimeout();
helpState = 0;
return true;
}
#endif
if ( inRegion == QPEDecoration::Help ) {
#ifdef WHATSTHIS_MODE
wtTimer->start( 400, TRUE );
#endif
helpState = QWSButton::Clicked|QWSButton::MouseOver;
drawButton( w, QPEDecoration::Help, helpState );
return true;
}
}
break;
case QEvent::MouseButtonRelease:
if ( helpState & QWSButton::Clicked ) {
wtTimer->stop();
helpState = 0;
drawButton( w, QPEDecoration::Help, helpState );
QPoint p = ((QMouseEvent*)e)->globalPos();
if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
decoration->help( w );
}
return true;
}
break;
case QEvent::MouseMove:
if ( helpState & QWSButton::Clicked ) {
int oldState = helpState;
QPoint p = ((QMouseEvent*)e)->globalPos();
if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
helpState = QWSButton::Clicked|QWSButton::MouseOver;
} else {
helpState = 0;
}
if ( helpState != oldState )
drawButton( w, QPEDecoration::Help, helpState );
}
break;
default:
break;
}
return QObject::eventFilter( o, e );
}
void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
{
QPainter painter(w);
QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
painter.internalGfx()->setWidgetDeviceRegion( rgn );
painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
}
void QPEManager::drawTitle( QWidget *w )
{
QPainter painter(w);
QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
painter.internalGfx()->setWidgetDeviceRegion( rgn );
painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
decoration->paint( &painter, w );
decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
}
@@ -658,257 +657,256 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor
int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
region = m & QRect( br.left(), br.top()+grab,
b, br.height()-2*grab );
}
break;
case Right:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
region = m & QRect( rect.right(), br.top()+grab,
b, br.height()-2*grab );
}
break;
case Bottom:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
region = m & QRect( br.left()+grab, rect.bottom(),
br.width()-2*grab, b );
}
break;
case TopLeft:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
QRegion crgn( br.left(), br.top(), grab, tb );
crgn |= QRect( br.left(), br.top(), lb, grab );
region = m & crgn;
}
break;
case TopRight:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
QRegion crgn( br.right()-grab, br.top(), grab, tb );
crgn |= QRect( br.right()-rb, br.top(), rb, grab );
region = m & crgn;
}
break;
case BottomLeft:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
}
break;
case BottomRight:
if ( !widget->isMaximized() ) {
QRegion m = wdiface->mask(&wd);
QRect br = m.boundingRect();
region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
}
break;
case All:
if ( widget->isMaximized() )
region = QWSDefaultDecoration::region(widget, rect, type);
else
region = wdiface->mask(&wd) - rect;
break;
default:
region = QWSDefaultDecoration::region(widget, rect, type);
break;
}
return region;
}
void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
{
WindowDecorationInterface::WindowData wd;
windowData( widget, wd );
int titleWidth = getTitleWidth(widget);
int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
QRect rect(widget->rect());
// title bar rect
QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
#ifndef QT_NO_PALETTE
QRegion oldClip = painter->clipRegion();
painter->setClipRegion( oldClip - QRegion( tr ) ); // reduce flicker
wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
painter->setClipRegion( oldClip );
if (titleWidth > 0) {
const QColorGroup &cg = widget->palette().active();
QBrush titleBrush;
QPen titlePen;
if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
titleBrush = cg.brush(QColorGroup::Highlight);
titlePen = cg.color(QColorGroup::HighlightedText);
} else {
titleBrush = cg.brush(QColorGroup::Background);
titlePen = cg.color(QColorGroup::Text);
}
wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
// Draw caption
painter->setPen(titlePen);
QFont f( QApplication::font() );
f.setWeight( QFont::Bold );
painter->setFont(f);
wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
}
#endif //QT_NO_PALETTE
paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
}
void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
QWSDecoration::Region type, int state)
{
WindowDecorationInterface::Button b;
switch ((int)type) {
case Close:
b = WindowDecorationInterface::Close;
break;
case Minimize:
if ( ((HackWidget *)w)->needsOk() )
b = WindowDecorationInterface::OK;
else if ( helpExists )
b = WindowDecorationInterface::Help;
else
return;
break;
case Help:
b = WindowDecorationInterface::Help;
break;
case Maximize:
b = WindowDecorationInterface::Maximize;
break;
default:
return;
}
WindowDecorationInterface::WindowData wd;
windowData( w, wd );
int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
QRect rect(w->rect());
QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
QRect brect(region(w, w->rect(), type).boundingRect());
const QColorGroup &cg = w->palette().active();
if ( wd.flags & WindowDecorationInterface::WindowData::Active )
painter->setPen( cg.color(QColorGroup::HighlightedText) );
else
painter->setPen( cg.color(QColorGroup::Text) );
QRegion oldClip = painter->clipRegion();
painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker
wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
painter->setClipRegion( oldClip );
}
//#define QPE_DONT_SHOW_TITLEBAR
void QPEDecoration::maximize( QWidget *widget )
{
#ifdef QPE_DONT_SHOW_TITLEBAR
if ( !widget->inherits( "QDialog" ) ) {
widget->setGeometry( qt_maxWindowRect );
} else
#endif
{
QWSDecoration::maximize( widget );
}
}
#ifndef QT_NO_DIALOG
class HackDialog : public QDialog
{
public:
void acceptIt() {
if ( isA( "QMessageBox" ) )
qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
else
accept();
}
};
#endif
void QPEDecoration::minimize( QWidget *widget )
{
#ifndef QT_NO_DIALOG
// We use the minimize button as an "accept" button.
if ( widget->inherits( "QDialog" ) ) {
HackDialog *d = (HackDialog *)widget;
d->acceptIt();
}
#endif
else if ( ((HackWidget *)widget)->needsOk() ) {
QSignal s;
s.connect( widget, SLOT( accept() ) );
s.activate();
} else {
help( widget );
}
}
void QPEDecoration::help( QWidget *w )
{
if ( helpExists ) {
Global::execute( "helpbrowser", helpFile );
} else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
QWhatsThis::enterWhatsThisMode();
QWhatsThis::leaveWhatsThisMode( qApp->tr(
"<Qt>Comprehensive help is not available for this application, "
"however there is context-sensitive help.<p>To use context-sensitive help:<p>"
"<ol><li>click and hold the help button."
"<li>when the title bar shows <b>What's this...</b>, "
"click on any control.</ol></Qt>" ) );
}
}
void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
{
wd.rect = w->rect();
if ( qpeManager->whatsThisWidget() == w )
wd.caption = qApp->tr("What's this..." );
else
wd.caption = w->caption();
wd.palette = qApp->palette();
wd.flags = 0;
wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
const QWidget *active = qpeManager->activeWidget();
wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
wd.reserved = 1;
}
/*
#ifndef QT_NO_POPUPMENU
QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
{
return 0;
}
#endif
*/
#endif // QT_NO_QWS_QPE_WM_STYLE
-#endif
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index 9436867..2e5a433 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,275 +1,271 @@
/**********************************************************************
** 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_TZSELECT_INC_LOCAL
#include "tzselect.h"
#include "resource.h"
#include "global.h"
#include "config.h"
#include <qtoolbutton.h>
#include <qfile.h>
#include <stdlib.h>
-#ifdef Q_WS_QWS
#include <qcopchannel_qws.h>
-#endif
class TimeZoneSelectorPrivate
{
public:
TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
bool includeLocal;
};
TZCombo::TZCombo( QWidget *p, const char* n )
: QComboBox( p, n )
{
updateZones();
// check to see if TZ is set, if it is set the current item to that
QString tz = getenv("TZ");
if (parent()->inherits("TimeZoneSelector")) {
if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
// overide to the 'local' type.
tz = "None";
}
}
if ( !tz.isNull() ) {
int n = 0,
index = 0;
for ( QStringList::Iterator it=identifiers.begin();
it!=identifiers.end(); ++it) {
if ( *it == tz )
index = n;
n++;
}
setCurrentItem(index);
} else {
setCurrentItem(0);
}
// listen on QPE/System
-#if defined(Q_WS_QWS)
#if !defined(QT_NO_COP)
QCopChannel *channel = new QCopChannel( "QPE/System", this );
connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) );
#endif
-#endif
}
TZCombo::~TZCombo()
{
}
void TZCombo::updateZones()
{
QString cur = currentText();
clear();
identifiers.clear();
int curix=0;
QString tz = getenv("TZ");
bool tzFound = FALSE;
Config cfg("CityTime");
cfg.setGroup("TimeZones");
int listIndex = 0;
if (parent()->inherits("TimeZoneSelector")) {
if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
// overide to the 'local' type.
identifiers.append( "None" );
insertItem( tr("None") );
if ( cur == tr("None"))
curix = 0;
listIndex++;
}
}
int cfgIndex = 0;
while (1) {
QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null);
if ( zn.isNull() )
break;
if ( zn == tz )
tzFound = TRUE;
QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex));
identifiers.append(zn);
insertItem(nm);
if ( nm == cur )
curix = listIndex;
++cfgIndex;
++listIndex;
}
if ( !listIndex ) {
QStringList list = timezoneDefaults();
for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
QString zn = *it;
QString nm = *++it;
if ( zn == tz )
tzFound = TRUE;
if ( nm == cur )
curix = listIndex;
identifiers.append(zn);
insertItem(nm);
++listIndex;
}
}
for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
insertItem(*it);
identifiers.append(*it);
if ( *it == cur )
curix = listIndex;
++listIndex;
}
if ( !tzFound && !tz.isEmpty()) {
int i = tz.find( '/' );
QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " ");
identifiers.append(tz);
insertItem(nm);
if ( nm == cur )
curix = listIndex;
++listIndex;
}
setCurrentItem(curix);
}
void TZCombo::keyPressEvent( QKeyEvent *e )
{
// ### should popup() in Qt 3.0 (it's virtual there)
// updateZones();
QComboBox::keyPressEvent(e);
}
void TZCombo::mousePressEvent(QMouseEvent*e)
{
// ### should popup() in Qt 3.0 (it's virtual there)
// updateZones();
QComboBox::mousePressEvent(e);
}
QString TZCombo::currZone() const
{
return identifiers[currentItem()];
}
void TZCombo::setCurrZone( const QString& id )
{
for (int i=0; i< count(); i++) {
if ( identifiers[i] == id ) {
setCurrentItem(i);
return;
}
}
insertItem(id);
setCurrentItem( count() - 1);
identifiers.append(id);
extras.append(id);
}
void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
{
if ( msg == "timeZoneListChange()" ) {
updateZones();
}
}
TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
QHBox(p,n)
{
d = new TimeZoneSelectorPrivate();
// build the combobox before we do any updates...
cmbTz = new TZCombo( this, "timezone combo" );
cmdTz = new QToolButton( this, "timezone button" );
cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) );
cmdTz->setMaximumSize( cmdTz->sizeHint() );
// set up a connection to catch a newly selected item and throw our
// signal
QObject::connect( cmbTz, SIGNAL( activated( int ) ),
this, SLOT( slotTzActive( int ) ) );
QObject::connect( cmdTz, SIGNAL( clicked() ),
this, SLOT( slotExecute() ) );
}
TimeZoneSelector::~TimeZoneSelector()
{
}
void TimeZoneSelector::setLocalIncluded(bool b)
{
d->includeLocal = b;
cmbTz->updateZones();
}
bool TimeZoneSelector::localIncluded() const
{
return d->includeLocal;
}
QString TimeZoneSelector::currentZone() const
{
return cmbTz->currZone();
}
void TimeZoneSelector::setCurrentZone( const QString& id )
{
cmbTz->setCurrZone( id );
}
void TimeZoneSelector::slotTzActive( int )
{
emit signalNewTz( cmbTz->currZone() );
}
void TimeZoneSelector::slotExecute( void )
{
// execute the world time application...
Global::execute( "citytime" );
}
QStringList timezoneDefaults( void )
{
QStringList tzs;
// load up the list just like the file format (citytime.cpp)
tzs.append( "America/New_York" );
tzs.append( "New York" );
tzs.append( "America/Los_Angeles" );
tzs.append( "Los Angeles" );
tzs.append( "Australia/Brisbane" );
tzs.append( "Brisbane" );
tzs.append( "Europe/Berlin" );
tzs.append( "Berlin" );
tzs.append( "Asia/Tokyo" );
tzs.append( "Tokyo" );
tzs.append( "America/Denver" );
tzs.append( "Denver" );
return tzs;
}