summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--library/alarmserver.cpp5
-rw-r--r--library/applnk.cpp4
-rw-r--r--library/categoryedit_p.cpp3
-rw-r--r--library/categorymenu.cpp2
-rw-r--r--library/config.cpp2
-rw-r--r--library/datebookdb.cpp5
-rw-r--r--library/datebookmonth.cpp5
-rw-r--r--library/filemanager.cpp3
-rw-r--r--library/fileselector.cpp2
-rw-r--r--library/finddialog.cpp1
-rw-r--r--library/findwidget_p.cpp6
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/global.cpp2
-rw-r--r--library/imageedit.cpp1
-rw-r--r--library/ir.cpp2
-rw-r--r--library/lnkproperties.cpp3
-rw-r--r--library/mimetype.cpp4
-rw-r--r--library/qcopenvelope_qws.cpp2
-rw-r--r--library/qdawg.cpp2
-rw-r--r--library/qpeapplication.cpp1
-rw-r--r--library/qpemenubar.cpp1
-rw-r--r--library/qpestyle.cpp3
-rw-r--r--library/qpetoolbar.cpp2
-rw-r--r--library/qt_override.cpp2
-rw-r--r--library/resource.cpp3
-rw-r--r--library/sound.cpp2
-rw-r--r--library/storage.cpp4
-rw-r--r--library/tzselect.cpp1
28 files changed, 1 insertions, 74 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 6f6f32d..48ab9c1 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,512 +1,507 @@
/**********************************************************************
** 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"
#include <qpe/qcopenvelope_qws.h>
#include "alarmserver.h"
#include <qpe/timeconversion.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#undef USE_ATD // not used anymore -- we run opie-alarm on suspend/resume
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 );
#ifdef USE_ATD
private:
QString atfilename;
#endif
};
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();
}
}
#ifdef USE_ATD
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) ) {
if ( trigger.writeBlock("\n", 2) != 2 ) {
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;
}
#else
static bool writeResumeAt ( time_t wakeup )
{
FILE *fp = ::fopen ( "/var/run/resumeat", "w" );
if ( fp ) {
::fprintf ( fp, "%d\n", (int) wakeup );
::fclose ( fp );
}
else
qWarning ( "Failed to write wakeup time to /var/run/resumeat" );
return ( fp );
}
#endif
void TimerReceiverObject::deleteTimer()
{
#ifdef USE_ATD
if ( !atfilename.isEmpty() ) {
unlink( atfilename );
atfilename = QString::null;
triggerAtd( FALSE );
}
#else
writeResumeAt ( 0 );
#endif
}
void TimerReceiverObject::resetTimer()
{
const int maxsecs = 2147000;
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);
#ifdef USE_ATD
QString fn = atdir + QString::number(at_secs) + "."
+ QString::number(getpid());
if ( fn != atfilename ) {
QFile atfile(fn + ".new");
if ( atfile.open(IO_WriteOnly | IO_Raw) ) {
int total_written;
// 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());
}
}
#else
writeResumeAt ( at_secs );
#endif
// 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.
A small example on how to use AlarmServer.
First we need to connect a slot the AppMessage QCOP call. appMessage
will be emitted if QPE/Application/appname gets called.
\code
TestApp::TestApp(QWidget *parent, const char* name, WFlags fl )
: QMainWindow(parent,name,fl){
connect(qApp,SIGNAL(appMessage(const QCString&,const QByteArray&)),
this,SLOT(slotAppMessage(const QCString&,const QByteArray&)));
}
\endcode
To add / delete an alarm, you can use the static method AlarmServer::addAlarm and
AlarmServer::deleteAlarm. Note that an old (expired) alarm will automatically be deleted
from the alarmserver list, but a change in timing will have the effect, that both
alarms will be emitted. So if you change an Alarm be sure to delete the old one!
@see addAlarm
\code
QDateTime oldDt = oldAlarmDateTime();
QPEApplication::execDialog(ourDlg);
QDateTime newDt = ourDlg->dateTime();
if(newDt == oldDt ) return;
@slash* code is missing for unsetting an alarm *@slash
AlarmServer::deleteAlarm(oldDt,"QPE/Application/appname","checkAlarm(QDateTime,int)",0);
AlarmServer::addAlarm( newDt,"QPE/AlarmServer/appname","checkAlarm(QDateTime,int)",0);
\endcode
Now once the Alarm is emitted you need to check the appMessage and then do what you want.
\code
void TestApp::slotAppMessage(const QCString& str, const QByteArray& ar ){
QDataStream stream(ar,IO_ReadOnly);
if(str == "checkAlarm(QDateTime,int)" ){
QDateTime dt;
int a;
stream >> dt >> a;
// fire up alarm
}
}
\endcode
\ingroup qtopiaemb
\sa QCopEnvelope
@see QPEApplication::appMessage(const QCString&,const QByteArray&)
@see OPimMainWindow
@see ODevice::alarmSound()
@see Sound::soundAlarm()
*/
/*!
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.
If this function is called with exactly the same data as a previous
call the subsequent call is ignored, so there is only ever one alarm
with a given set of parameters.
Once an alarm is emitted. The \a channel with a \a message will be emitted
and data will be send.
The QDateTime and int are the two parameters included in the QCOP message.
You can specify channel, message and the integer parameter. QDateTime will be
the datetime of the QCop call.
@param when The QDateTime of the alarm
@param channel The channel which gets called once the alarm is emitted
@param message The message to be send to the channel
@param data Additional data as integer
@see QCopChannel
\sa deleteAlarm()
*/
void AlarmServer::addAlarm ( QDateTime when, const QCString& channel,
const QCString& message, int data)
{
if ( qApp->type() == QApplication::GuiServer ) {
bool needSave = FALSE;
// Here we are the server so either it has been directly called from
// within the server or it has been sent to us from a client via QCop
if (!timerEventReceiver)
timerEventReceiver = new TimerReceiverObject;
timerEventItem *newTimerEventItem = new timerEventItem;
newTimerEventItem->UTCtime = TimeConversion::toUTC( when );
newTimerEventItem->channel = channel;
newTimerEventItem->message = message;
newTimerEventItem->data = data;
// explore the case of already having the event in here...
QListIterator<timerEventItem> it( timerEventList );
for ( ; *it; ++it )
if ( *(*it) == *newTimerEventItem )
return ;
// if we made it here, it is okay to add the item...
timerEventList.append( newTimerEventItem );
needSave = TRUE;
// quicker than using setNearestTimerEvent()
if ( nearestTimerEvent ) {
if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) {
nearestTimerEvent = newTimerEventItem;
timerEventReceiver->killTimers();
timerEventReceiver->resetTimer();
}
}
else {
nearestTimerEvent = newTimerEventItem;
timerEventReceiver->resetTimer();
}
if ( needSave )
saveState();
}
else {
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" );
e << when << channel << message << data;
#endif
}
}
/*!
Deletes previously scheduled alarms which match \a when, \a channel,
\a message, and \a data.
Passing null values for \a when, \a channel, or for the \link
qcop.html QCop\endlink \a message, acts as a wildcard meaning "any".
Similarly, passing -1 for \a data indicates "any".
If there is no matching alarm, nothing happens.
\sa addAlarm()
*/
void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data)
{
if ( qApp->type() == QApplication::GuiServer) {
bool needSave = FALSE;
if ( timerEventReceiver != NULL ) {
timerEventReceiver->killTimers();
// iterate over the list of events
QListIterator<timerEventItem> it( timerEventList );
time_t deleteTime = TimeConversion::toUTC( when );
for ( ; *it; ++it ) {
// if its a match, delete it
if ( ( (*it)->UTCtime == deleteTime || when.isNull() )
&& ( channel.isNull() || (*it)->channel == channel )
&& ( message.isNull() || (*it)->message == message )
&& ( data == -1 || (*it)->data == data ) ) {
// if it's first, then we need to update the timer
if ( (*it) == nearestTimerEvent ) {
timerEventList.remove(*it);
setNearestTimerEvent();
}
else {
timerEventList.remove(*it);
}
needSave = TRUE;
}
}
if ( nearestTimerEvent )
timerEventReceiver->resetTimer();
}
if ( needSave )
saveState();
}
else {
#ifndef QT_NO_COP
QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" );
e << when << channel << message << data;
#endif
}
}
/*!
The implementation depends on the mode of AlarmServer. If the AlarmServer
uses atd the current system time will be written to the hardware clock.
If the AlarmServer relies on opie-alarm the time will be written once the
device gets suspended. opie-alarm is used by the Zaurus, iPAQs and SIMpad
*/
void Global::writeHWClock()
{
#ifdef USE_ATD
if ( !triggerAtd( TRUE ) ) {
// atd not running? set it ourselves
system("/sbin/hwclock --systohc"); // ##### UTC?
}
#else
// hwclock is written on suspend
#endif
}
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 8763eb2..9c60f1a 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,1497 +1,1493 @@
/**********************************************************************
** 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>
#include <qpe/qcopenvelope_qws.h>
-#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>
-#include <qgfx_qws.h>
#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() );
// we need to update the names for the mCat... to mCatList
mCatList.clear();
for (uint i = 0; i < mCat.count(); i++ )
mCatList << cat.label("Document View", mCat[i] );
}
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
that the application can view or edit.
*/
/*!
\fn const QArray<int>& AppLnk::categories() const
Returns the Categories property.
See the CategoryWidget for more details.
\sa setCategories()
*/
const QArray<int>& AppLnk::categories() const
{
d->ensureCatArray();
return d->mCat;
}
/*!
\fn int AppLnk::id() const
Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
this value is 0, otherwise it is a value that is unique for the
duration of the current process.
\sa AppLnkSet::find()
*/
/*!
\fn bool AppLnk::isValid() const
Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
*/
/*!
\fn bool AppLnk::fileKnown() const
If the with the AppLnk associated file is not equal to QString::null
*/
/*!
\fn bool AppLnk::linkFileKnown()const
The filename of the AppLnk
*/
/*!
\fn void AppLnk::setRotation( const QString& )
The default rotation of the associated application. This
function is included inline for binary compatible issues
*/
/*!
Creates an invalid AppLnk.
\sa isValid()
*/
AppLnk::AppLnk()
{
mId = 0;
d = new AppLnkPrivate();
}
/*!
Loads \a file (e.g. \e app.desktop) as an AppLnk.
\sa writeLink()
*/
AppLnk::AppLnk( const QString &file )
{
QStringList sl;
d = new AppLnkPrivate();
if ( !file.isNull() ) {
Config config( file, Config::File );
if ( config.isValid() ) {
config.setGroup( "Desktop Entry" );
mName = config.readEntry( "Name", file );
mExec = config.readEntry( "Exec" );
mType = config.readEntry( "Type", QString::null );
mIconFile = config.readEntry( "Icon", QString::null );
mRotation = config.readEntry( "Rotation", "" );
mComment = config.readEntry( "Comment", QString::null );
// MIME types are case-insensitive.
mMimeTypes = config.readListEntry( "MimeType", ';' );
for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
*it = (*it).lower();
mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
mLinkFile = file;
mFile = config.readEntry("File", QString::null);
if ( !mExec. isEmpty ( )) {
mFile = QString::null;
}
else if ( mFile[0] != '/' ) {
int slash = file.findRev('/');
if ( slash >= 0 ) {
mFile = file.left(slash) + '/' + mFile;
}
}
d->mCatList = config.readListEntry("Categories", ';');
if ( d->mCatList[0].toInt() < -1 ) {
// numeric cats in file! convert to text
Categories cat( 0 );
cat.load( categoryFileName() );
d->mCat.resize( d->mCatList.count() );
int i;
QStringList::ConstIterator it;
for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
++it, i++ ) {
bool number;
int id = (*it).toInt( &number );
if ( !number ) {
// convert from text
id = cat.id( "Document View", *it );
if ( id == 0 )
id = cat.addCategory( "Document View", *it );
}
d->mCat[i] = id;
}
d->updateCatListFromArray();
}
}
}
mId = 0;
}
AppLnk& AppLnk::operator=(const AppLnk &copy)
{
if ( this == &copy ) return *this;
if ( mId )
qWarning("Deleting AppLnk that is in an AppLnkSet");
if ( d )
delete d;
mName = copy.mName;
/* remove for Qtopia 3.0 -zecke */
mPixmap = copy.mPixmap;
mBigPixmap = copy.mBigPixmap;
mExec = copy.mExec;
mType = copy.mType;
mRotation = copy.mRotation;
mComment = copy.mComment;
mFile = copy.mFile;
mLinkFile = copy.mLinkFile;
mIconFile = copy.mIconFile;
mMimeTypes = copy.mMimeTypes;
mMimeTypeIcons = copy.mMimeTypeIcons;
mId = 0;
d = new AppLnkPrivate();
d->mCat = copy.d->mCat;
d->mCatList = copy.d->mCatList;
d->mPixmaps = copy.d->mPixmaps;
return *this;
}
/*!
protected internally to share code
should I document that at all?
I don't know the TT style for that
*/
const QPixmap& AppLnk::pixmap( int pos, int size ) const {
if ( d->mPixmaps[pos].isNull() ) {
AppLnk* that = (AppLnk*)this;
if ( mIconFile.isEmpty() ) {
MimeType mt(type());
that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
if ( that->d->mPixmaps[pos].isNull() )
that->d->mPixmaps[pos].convertFromImage(
Resource::loadImage("UnknownDocument")
.smoothScale( size, size ) );
return that->d->mPixmaps[pos];
}
QImage unscaledIcon = Resource::loadImage( that->mIconFile );
if ( unscaledIcon.isNull() ) {
// qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
that->d->mPixmaps[pos].convertFromImage(
Resource::loadImage("UnknownDocument")
.smoothScale( size, size ) );
} else {
that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
}
return that->d->mPixmaps[pos];
}
return d->mPixmaps[pos];
}
/*!
Returns a small pixmap associated with the application.
\sa bigPixmap() setIcon()
*/
const QPixmap& AppLnk::pixmap() const
{
if ( d->mPixmaps[0].isNull() ) {
return pixmap(AppLnkPrivate::Normal, smallSize );
}
return d->mPixmaps[0];
}
/*!
Returns a large pixmap associated with the application.
\sa pixmap() setIcon()
*/
const QPixmap& AppLnk::bigPixmap() const
{
if ( d->mPixmaps[1].isNull() ) {
return pixmap( AppLnkPrivate::Big, bigSize );
}
return d->mPixmaps[1];
}
/*!
Returns the type of the AppLnk. For applications, games and
settings the type is \c Application; for documents the type is the
document's MIME type.
*/
QString AppLnk::type() const
{
if ( mType.isNull() ) {
AppLnk* that = (AppLnk*)this;
QString f = file();
if ( !f.isNull() ) {
MimeType mt(f);
that->mType = mt.id();
return that->mType;
}
}
return mType;
}
/*!
Returns the file associated with the AppLnk.
\sa exec() name()
*/
QString AppLnk::file() const
{
if ( mExec.isEmpty ( ) && mFile.isNull() ) {
AppLnk* that = (AppLnk*)this;
QString ext = MimeType(mType).extension();
if ( !ext.isEmpty() )
ext = "." + ext;
if ( !mLinkFile.isEmpty() ) {
that->mFile =
mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
qDebug("mFile now == %s", mFile.latin1());
} else if ( mType.contains('/') ) {
that->mFile =
QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
/*
* A file with the same name or a .desktop file already exists
*/
if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
int n=1;
QString nn;
while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
|| QFile::exists(nn+".desktop"))
n++;
that->mFile = nn;
}
that->mLinkFile = that->mFile+".desktop";
that->mFile += ext;
}
prepareDirectories(that->mFile);
if ( !that->mFile.isEmpty() ) {
QFile f(that->mFile);
if ( !f.open(IO_WriteOnly) )
that->mFile = QString::null;
return that->mFile;
}
}
return mFile;
}
/*!
Returns the desktop file corresponding to this AppLnk.
\sa file() exec() name()
*/
QString AppLnk::linkFile() const
{
if ( mLinkFile.isNull() ) {
AppLnk* that = (AppLnk*)this;
if ( type().contains('/') ) {
StorageInfo storage;
const FileSystem *fs = storage.fileSystemOf( that->mFile );
/* tmpfs + and ramfs are available too but not removable
* either we fix storage or add this
*/
if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
that->mLinkFile = fs->path();
} else
that->mLinkFile = getenv( "HOME" );
that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
/* the desktop file exists make sure we don't point to the same file */
if ( QFile::exists(that->mLinkFile+".desktop") ) {
AppLnk lnk( that->mLinkFile + ".desktop" );
/* the linked is different */
if(that->file() != lnk.file() ) {
int n = 1;
QString nn;
while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) {
n++;
/* just to be sure */
AppLnk lnk(nn );
if (lnk.file() == that->file() )
break;
}
that->mLinkFile = nn;
}
}
that->mLinkFile += ".desktop";
storeLink();
}
return that->mLinkFile;
}
return mLinkFile;
}
/*!
Copies \a copy.
*/
AppLnk::AppLnk( const AppLnk &copy )
{
mName = copy.mName;
mPixmap = copy.mPixmap;
mBigPixmap = copy.mBigPixmap;
mExec = copy.mExec;
mType = copy.mType;
mRotation = copy.mRotation;
mComment = copy.mComment;
mFile = copy.mFile;
mLinkFile = copy.mLinkFile;
mIconFile = copy.mIconFile;
mMimeTypes = copy.mMimeTypes;
mMimeTypeIcons = copy.mMimeTypeIcons;
mId = 0;
d = new AppLnkPrivate();
d->mCat = copy.d->mCat;
d->mCatList = copy.d->mCatList;
d->mPixmaps = copy.d->mPixmaps;
}
/*!
Destroys the AppLnk. Note that if the AppLnk is currently a member
of an AppLnkSet, this will produce a run-time warning.
\sa AppLnkSet::add() AppLnkSet::remove()
*/
AppLnk::~AppLnk()
{
if ( mId )
qWarning("Deleting AppLnk that is in an AppLnkSet");
if ( d )
delete d;
}
/*!
\overload
Executes the application associated with this AppLnk.
\sa exec()
*/
void AppLnk::execute() const
{
execute(QStringList());
}
/*!
Executes the application associated with this AppLnk, with
\a args as arguments.
\sa exec()
*/
void AppLnk::execute(const QStringList& args) const
{
#ifdef Q_WS_QWS
if ( !mRotation.isEmpty() ) {
// ######## this will only work in the server
int rot = QPEApplication::defaultRotation();
rot = (rot+mRotation.toInt())%360;
QCString old = getenv("QWS_DISPLAY");
setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
invoke(args);
setenv("QWS_DISPLAY", old.data(), 1);
} else
#endif
invoke(args);
}
/*!
Invokes the application associated with this AppLnk, with
\a args as arguments. Rotation is not taken into account by
this function, so you should not call it directly.
\sa execute()
*/
void AppLnk::invoke(const QStringList& args) const
{
Global::execute( exec(), args[0] );
}
/*!
Sets the Exec property to \a exec.
\sa exec() name()
*/
void AppLnk::setExec( const QString& exec )
{
mExec = exec;
}
#if 0 // this was inlined for better BC
/*!
Sets the Rotation property to \a rot.
\sa rotation()
*/
void AppLnk::setRotation ( const QString &rot )
{
mRotation = rot;
}
#endif
/*!
Sets the Name property to \a docname.
\sa name()
*/
void AppLnk::setName( const QString& docname )
{
mName = docname;
}
/*!
Sets the File property to \a filename.
\sa file() name()
*/
void AppLnk::setFile( const QString& filename )
{
mFile = filename;
}
/*!
Sets the LinkFile property to \a filename.
\sa linkFile()
*/
void AppLnk::setLinkFile( const QString& filename )
{
mLinkFile = filename;
}
/*!
Sets the Comment property to \a comment.
This text is displayed in the 'Details Dialog', for example if the
user uses the 'press-and-hold' gesture.
\sa comment()
*/
void AppLnk::setComment( const QString& comment )
{
mComment = comment;
}
/*!
Sets the Type property to \a type.
For applications, games and settings the type should be \c
Application; for documents the type should be the document's MIME
type.
\sa type()
*/
void AppLnk::setType( const QString& type )
{
mType = type;
}
/*!
\fn QString AppLnk::icon() const
Returns the Icon property.
\sa setIcon()
*/
/*!
Sets the Icon property to \a iconname. This is the filename from
which the pixmap() and bigPixmap() are obtained.
\sa icon() setSmallIconSize() setBigIconSize()
*/
void AppLnk::setIcon( const QString& iconname )
{
mIconFile = iconname;
QImage unscaledIcon = Resource::loadImage( mIconFile );
d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
}
/*!
Sets the Categories property to \a c.
See the CategoryWidget for more details.
\sa categories()
*/
void AppLnk::setCategories( const QArray<int>& c )
{
d->mCat = c;
d->updateCatListFromArray();
}
/*!
\fn QStringList AppLnk::mimeTypeIcons() const
Returns the MimeTypeIcons property of the AppLnk.
*/
/*!
Attempts to ensure that the link file for this AppLnk exists,
including creating any required directories. Returns TRUE if
successful; otherwise returns FALSE.
You should not need to use this function.
*/
bool AppLnk::ensureLinkExists() const
{
QString lf = linkFile();
return prepareDirectories(lf);
}
/*!
Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
otherwise returns FALSE.
In addition, the "linkChanged(QString)" message is sent to the
"QPE/System" \link qcop.html QCop\endlink channel.
*/
bool AppLnk::writeLink() const
{
// Only re-writes settable parts
QString lf = linkFile();
if ( !ensureLinkExists() )
return FALSE;
storeLink();
return TRUE;
}
/*!
\internal
*/
void AppLnk::storeLink() const
{
Config config( mLinkFile, Config::File );
config.setGroup("Desktop Entry");
config.writeEntry("Name",mName);
if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
config.writeEntry("Type",type());
if(!rotation().isEmpty())
config.writeEntry("Rotation",rotation());
else
config.removeEntry("Rotation");
if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
QString f = file();
int i = 0;
while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
i++;
while ( i && f[i] != '/' )
i--;
// simple case where in the same directory
if ( mLinkFile.find( '/', i + 1 ) < 0 )
f = f.mid(i+1);
// ### could do relative ie ../../otherDocs/file.doc
config.writeEntry("File",f);
config.writeEntry( "Categories", d->mCatList, ';' );
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
e << mLinkFile;
#endif
}
/*!
Sets the property named \a key to \a value.
\sa property()
*/
void AppLnk::setProperty(const QString& key, const QString& value)
{
if ( ensureLinkExists() ) {
Config cfg(linkFile(), Config::File);
cfg.writeEntry(key,value);
}
}
/*!
Returns the property named \a key.
\sa setProperty()
*/
QString AppLnk::property(const QString& key) const
{
QString lf = linkFile();
if ( !QFile::exists(lf) )
return QString::null;
Config cfg(lf, Config::File);
return cfg.readEntry(key);
}
bool AppLnk::isPreloaded() const {
// Preload information is stored in the Launcher config in v1.5.
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps",',');
if (apps.contains(exec()))
return true;
return false;
}
void AppLnk::setPreloaded(bool yesNo) {
// Preload information is stored in the Launcher config in v1.5.
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps", ',');
if (apps.contains(exec()) && !yesNo)
apps.remove(exec());
else if (yesNo && !apps.contains(exec()))
apps.append(exec());
cfg.writeEntry("Apps", apps, ',');
}
/*!
Deletes both the linkFile() and the file() associated with this AppLnk.
\sa removeLinkFile()
*/
void AppLnk::removeFiles()
{
bool valid = isValid();
if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
if ( QFile::remove(file()) ) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
if ( linkFileKnown() )
e << linkFile();
else
e << file();
#endif
} else if ( valid ) {
// restore link
writeLink();
}
}
}
/*!
Deletes the linkFile(), leaving any file() untouched.
\sa removeFiles()
*/
void AppLnk::removeLinkFile()
{
if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "linkChanged(QString)");
e << linkFile();
#endif
}
}
class AppLnkSetPrivate {
public:
AppLnkSetPrivate()
{
typPix.setAutoDelete(TRUE);
typPixBig.setAutoDelete(TRUE);
typName.setAutoDelete(TRUE);
}
QDict<QPixmap> typPix;
QDict<QPixmap> typPixBig;
QDict<QString> typName;
};
/*!
\class AppLnkSet applnk.h
\brief The AppLnkSet class is a set of AppLnk objects.
*/
/*!
\fn QStringList AppLnkSet::types() const
Returns the list of \link applnk.html#Types types\endlink in the set.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
\sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
*/
/*!
\fn const QList<AppLnk>& AppLnkSet::children() const
Returns the members of the set.
*/
/*!
Constructs an empty AppLnkSet.
*/
AppLnkSet::AppLnkSet() :
d(new AppLnkSetPrivate)
{
}
/*!
Constructs an AppLnkSet that contains AppLnk objects representing
all the files in the given \a directory (and any subdirectories
recursively).
\omit
The directories may contain ".directory" files which override
any AppLnk::type() values for AppLnk objects found in the directory.
This allows simple localization of application types.
\endomit
*/
AppLnkSet::AppLnkSet( const QString &directory ) :
d(new AppLnkSetPrivate)
{
QDir dir( directory );
mFile = directory;
findChildren(directory,QString::null,QString::null);
}
/*!
Detaches all AppLnk objects from the set. The set become empty and
the caller becomes responsible for deleting the AppLnk objects.
*/
void AppLnkSet::detachChildren()
{
QListIterator<AppLnk> it( mApps );
for ( ; it.current(); ) {
AppLnk* a = *it;
++it;
a->mId = 0;
}
mApps.clear();
}
/*!
Destroys the set, deleting all the AppLnk objects it contains.
\sa detachChildren()
*/
AppLnkSet::~AppLnkSet()
{
QListIterator<AppLnk> it( mApps );
for ( ; it.current(); ) {
AppLnk* a = *it;
++it;
a->mId = 0;
delete a;
}
delete d;
}
void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
{
depth++;
if ( depth > 10 )
return;
QDir dir( dr );
QString typNameLocal = typName;
if ( dir.exists( ".directory" ) ) {
Config config( dr + "/.directory", Config::File );
config.setGroup( "Desktop Entry" );
typNameLocal = config.readEntry( "Name", typNameLocal );
if ( !typ.isEmpty() ) {
QString iconFile = config.readEntry( "Icon", "AppsIcon" );
QImage unscaledIcon = Resource::loadImage( iconFile );
QPixmap pm, bpm;
pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
d->typPix.insert(typ, new QPixmap(pm));
d->typPixBig.insert(typ, new QPixmap(bpm));
d->typName.insert(typ, new QString(typNameLocal));
}
}
const QFileInfoList *list = dir.entryInfoList();
if ( list ) {
QFileInfo* fi;
bool cadded=FALSE;
for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
QString bn = fi->fileName();
// qDebug("findChildren "+bn);
if ( bn[0] != '.' && bn != "CVS" ) {
if ( fi->isDir() ) {
QString c = typ.isNull() ? bn : typ+"/"+bn;
QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
findChildren(fi->filePath(), c, d, depth );
} else {
if ( fi->extension(FALSE) == "desktop" ) {
AppLnk* app = new AppLnk( fi->filePath() );
#ifdef QT_NO_QWS_MULTIPROCESS
if ( !Global::isBuiltinCommand( app->exec() ) )
delete app;
else
#endif
{
if ( !typ.isEmpty() ) {
if ( !cadded ) {
typs.append(typ);
cadded = TRUE;
}
app->setType(typ);
}
add(app);
}
}
}
}
}
}
}
/*!
Adds AppLnk \a f to the set. The set takes responsibility for
deleting \a f.
\sa remove()
*/
void AppLnkSet::add( AppLnk *f )
{
if ( f->mId == 0 ) {
AppLnk::lastId++;
f->mId = AppLnk::lastId;
mApps.append( f );
} else {
qWarning("Attempt to add an AppLnk twice");
}
}
/*!
Removes AppLnk \a f to the set. The caller becomes responsible for
deleting \a f. Returns TRUE if \a f was in the set; otherwise
returns FALSE.
\sa add()
*/
bool AppLnkSet::remove( AppLnk *f )
{
if ( mApps.remove( f ) ) {
f->mId = 0;
return TRUE;
}
return FALSE;
}
/*!
Returns the localized name for type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QString AppLnkSet::typeName( const QString& t ) const
{
QString *st = d->typName.find(t);
return st ? *st : QString::null;
}
/*!
Returns the small pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typePixmap( const QString& t ) const
{
QPixmap *pm = d->typPix.find(t);
return pm ? *pm : QPixmap();
}
/*!
Returns the large pixmap associated with type \a t.
For applications, games and settings the type is \c Application;
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
{
QPixmap *pm = d->typPixBig.find(t);
return pm ? *pm : QPixmap();
}
/*!
Returns the AppLnk with the given \a id.
*/
const AppLnk *AppLnkSet::find( int id ) const
{
QListIterator<AppLnk> it( children() );
for ( ; it.current(); ++it ) {
const AppLnk *app = it.current();
if ( app->id() == id )
return app;
}
return 0;
}
/*!
Returns the AppLnk with the given \a exec attribute.
*/
const AppLnk *AppLnkSet::findExec( const QString& exec ) const
{
QListIterator<AppLnk> it( children() );
for ( ; it.current(); ++it ) {
const AppLnk *app = it.current();
if ( app->exec() == exec )
return app;
}
return 0;
}
/*!
\class DocLnkSet applnk.h
\brief The DocLnkSet class is a set of DocLnk objects.
*/
/*!
\fn const QList<DocLnk>& DocLnkSet::children() const
Returns the members of the set.
*/
/*!
Constructs an empty DocLnkSet.
\sa appendFrom()
*/
DocLnkSet::DocLnkSet()
{
}
/*!
Constructs a DocLnkSet that contains DocLnk objects representing all
the files in the \a directory (and any subdirectories, recursively).
If \a mimefilter is not null,
only documents with a MIME type matching \a mimefilter are selected.
The value may contain multiple wild-card patterns separated by ";",
such as \c{*o/mpeg;audio/x-wav}.
See also \link applnk.html#files-and-links Files and Links\endlink.
*/
DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
AppLnkSet()
{
QDir dir( directory );
mFile = dir.dirName();
QDict<void> reference;
QStringList subFilter = QStringList::split(";", mimefilter);
QValueList<QRegExp> mimeFilters;
for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
findChildren(directory, mimeFilters, reference);
const QList<DocLnk> &list = children();
for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
reference.remove( (*it)->file() );
}
for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
if ( dit.current() == (void*)2 ) {
// Unreferenced, make an unwritten link
DocLnk* dl = new DocLnk;
QFileInfo fi( dit.currentKey() );
dl->setFile(fi.filePath());
dl->setName(fi.baseName());
// #### default to current path?
// dl->setCategories( ... );
bool match = mimefilter.isNull();
if ( !match )
for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
if ( (*it).match(dl->type()) >= 0 )
match = TRUE;
if ( match /* && dl->type() != "application/octet-stream" */
&& !!dl->exec() )
add(dl);
else
delete dl;
}
}
}
// other becomes empty
/*!
Transfers all DocLnk objects from \a other to this set. \a other becomes
empty.
*/
void DocLnkSet::appendFrom( DocLnkSet& other )
{
if ( &other == this )
return;
QListIterator<AppLnk> it( other.mApps );
for ( ; it.current(); ) {
mApps.append(*it);
++it;
}
other.mApps.clear();
}
void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
{
depth++;
if ( depth > 10 )
return;
QDir dir( dr );
/* Opie got a different approach
* I guess it's geek vs. consumer
* in this case to be discussed
*/
if ( dir.exists( ".Qtopia-ignore" ) )
return;
const QFileInfoList *list = dir.entryInfoList();
if ( list ) {
QFileInfo* fi;
for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
QString bn = fi->fileName();
if ( bn[0] != '.' ) {
if ( fi->isDir() ) {
if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
findChildren(fi->filePath(), mimeFilters, reference, depth);
} else {
if ( fi->extension(FALSE) == "desktop" ) {
DocLnk* dl = new DocLnk( fi->filePath() );
QFileInfo fi2(dl->file());
bool match = FALSE;
if ( !fi2.exists() ) {
dir.remove( dl->file() );
}
if ( mimeFilters.count() == 0 ) {
add( dl );
match = TRUE;
} else {
for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
if ( (*it).match(dl->type()) >= 0 ) {
add(dl);
match = TRUE;
}
}
}
if ( !match )
delete dl;
} else {
if ( !reference.find(fi->fileName()) )
reference.insert(fi->filePath(), (void*)2);
}
}
}
}
}
}
/*!
\class DocLnk applnk.h
\brief The DocLnk class represents loaded document references.
*/
/*!
\fn DocLnk::DocLnk( const DocLnk &o )
Copies \a o.
*/
/*!
Constructs a DocLnk from a valid .desktop \a file or a new .desktop
\a file for other files.
*/
DocLnk::DocLnk( const QString &file ) :
AppLnk(file)
{
init(file);
}
/*!
Constructs a DocLnk from a valid .desktop \a file or a new .desktop
\a file for other files. If \a may_be_desktopfile is TRUE, then an
attempt is made to read \a file as a .desktop file; if that fails it
is read as a normal file.
*/
DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :
AppLnk(may_be_desktopfile ? file : QString::null)
{
init(file);
}
void DocLnk::init(const QString &file)
{
if ( isValid() ) {
#ifndef FORCED_DIR_STRUCTURE_WAY
if ( mType.isNull() )
// try to infer it
#endif
{
int s0 = file.findRev('/');
if ( s0 > 0 ) {
int s1 = file.findRev('/',s0-1);
if ( s1 > 0 ) {
int s2 = file.findRev('/',s1-1);
if ( s2 > 0 ) {
mType = file.mid(s2+1,s0-s2-1);
}
}
}
}
} else if ( QFile::exists(file) ) {
QString n = file;
n.replace(QRegExp(".*/"),"");
n.replace(QRegExp("\\..*"),"");
setName( n );
setFile( file );
}
MimeType mt(mType);
if( mt.application() )
mExec = mt.application()->exec();
}
/*!
Constructs an invalid DocLnk.
*/
DocLnk::DocLnk()
{
}
/*!
Destroys the DocLnk. Just like AppLnk objects, a run-time error
occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).
*/
DocLnk::~DocLnk()
{
}
/*!
\reimp
*/
QString DocLnk::exec() const
{
MimeType mt(type());
const AppLnk* app = mt.application();
if ( app )
return app->exec();
else
return QString::null;
}
/*!
\reimp
*/
void DocLnk::invoke(const QStringList& args) const
{
MimeType mt(type());
const AppLnk* app = mt.application();
if ( app ) {
QStringList a = args;
if ( linkFileKnown() && QFile::exists( linkFile() ) )
a.append(linkFile());
else
a.append(file());
app->execute(a);
}
}
diff --git a/library/categoryedit_p.cpp b/library/categoryedit_p.cpp
index 9321259..14ac2e1 100644
--- a/library/categoryedit_p.cpp
+++ b/library/categoryedit_p.cpp
@@ -1,230 +1,227 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of 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 "categoryedit_p.h"
#include <qpe/categories.h>
#include <qdir.h>
#include <qcheckbox.h>
#include <qlineedit.h>
-#include <qlistview.h>
-#include <qstringlist.h>
-#include <qtoolbutton.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
using namespace Qtopia;
class CategoryEditPrivate
{
public:
CategoryEditPrivate( QWidget *parent, const QString &appName )
: mCategories( parent, "" ),
mStrApp( appName )
{
editItem = 0;
mCategories.load( categoryFileName() );
}
Categories mCategories;
QListViewItem *editItem;
QString mStrApp;
QString mVisible;
};
CategoryEdit::CategoryEdit( QWidget *parent, const char *name )
: CategoryEditBase( parent, name )
{
d = 0;
}
CategoryEdit::CategoryEdit( const QArray<int> &recCats,
const QString &appName, const QString &visibleName,
QWidget *parent, const char *name )
: CategoryEditBase( parent, name )
{
d = 0;
setCategories( recCats, appName, visibleName );
}
void CategoryEdit::setCategories( const QArray<int> &recCats,
const QString &appName, const QString &visibleName )
{
if ( !d )
d = new CategoryEditPrivate( (QWidget*)parent(), name() );
d->mStrApp = appName;
d->mVisible = visibleName;
QStringList appCats = d->mCategories.labels( d->mStrApp );
QArray<int> cats = d->mCategories.ids(d->mStrApp, appCats);
lvView->clear();
QStringList::ConstIterator it;
int i, j;
for ( i = 0, it = appCats.begin(); it != appCats.end(); i++, ++it ) {
QCheckListItem *chk;
chk = new QCheckListItem( lvView, (*it), QCheckListItem::CheckBox );
if ( !d->mCategories.isGlobal((*it)) )
chk->setText( 1, tr(d->mVisible) );
else
chk->setText( 1, tr("All") );
// Is this record using this category, then we should check it
for ( j = 0; j < int(recCats.count()); j++ ) {
if ( cats[i] == recCats[j] ) {
chk->setOn( true );
break;
}
}
}
lvView->setSorting( 0, TRUE );
lvView->sort();
if ( lvView->childCount() < 1 )
txtCat->setEnabled( FALSE );
else {
lvView->setSelected( lvView->firstChild(), true );
}
}
CategoryEdit::~CategoryEdit()
{
if ( d )
delete d;
}
void CategoryEdit::slotSetText( QListViewItem *selected )
{
d->editItem = selected;
if ( !d->editItem )
return;
txtCat->setText( d->editItem->text(0) );
txtCat->setEnabled( true );
if ( d->editItem->text(1) == tr("All") )
chkGlobal->setChecked( true );
else
chkGlobal->setChecked( false );
}
void CategoryEdit::slotAdd()
{
QString name = tr( "New Category" );
bool insertOk = FALSE;
int num = 0;
while ( !insertOk ) {
if ( num++ > 0 )
name = tr("New Category ") + QString::number(num);
insertOk = d->mCategories.addCategory( d->mStrApp, name );
}
QCheckListItem *chk;
chk = new QCheckListItem( lvView, name, QCheckListItem::CheckBox );
if ( !chkGlobal->isChecked() )
chk->setText( 1, tr(d->mVisible) );
else
chk->setText( 1, tr("All") );
lvView->setSelected( chk, TRUE );
txtCat->selectAll();
txtCat->setFocus();
}
void CategoryEdit::slotRemove()
{
d->editItem = lvView->selectedItem();
if ( d->editItem ) {
QListViewItem *sibling = d->editItem->nextSibling();
d->mCategories.removeCategory( d->mStrApp, d->editItem->text(0) );
delete d->editItem;
d->editItem = 0;
if ( sibling )
lvView->setSelected( sibling, TRUE );
}
if ( lvView->childCount() < 1 ) {
txtCat->clear();
txtCat->setEnabled( FALSE );
}
}
void CategoryEdit::slotSetGlobal( bool isChecked )
{
if ( d->editItem ) {
if ( isChecked )
d->editItem->setText( 1, tr("All") );
else
d->editItem->setText( 1, tr(d->mVisible) );
d->mCategories.setGlobal( d->mStrApp, d->editItem->text( 0 ), isChecked );
}
}
void CategoryEdit::slotTextChanged( const QString &strNew )
{
if ( d->editItem ) {
if ( chkGlobal->isChecked() )
d->mCategories.renameGlobalCategory( d->editItem->text(0), strNew );
else
d->mCategories.renameCategory( d->mStrApp, d->editItem->text(0), strNew );
d->editItem->setText( 0, strNew );
}
}
QArray<int> CategoryEdit::newCategories()
{
QArray<int> a;
if ( d ) {
d->mCategories.save( categoryFileName() );
QListViewItemIterator it( lvView );
QValueList<int> l;
for ( ; it.current(); ++it ) {
if ( reinterpret_cast<QCheckListItem*>(it.current())->isOn() )
l.append( d->mCategories.id( d->mStrApp, it.current()->text(0) ) );
}
uint i = 0;
a.resize( l.count() );
for ( QValueList<int>::Iterator lit = l.begin(); lit != l.end(); ++lit )
a[i++] = *lit;
}
return a;
}
void CategoryEdit::accept()
{
// write our categories out...
d->mCategories.save( categoryFileName() );
// QDialog::accept();
}
QString categoryFileName()
{
QDir dir = (QString(getenv("HOME")) + "/Settings");
if ( !dir.exists() )
mkdir( dir.path().local8Bit(), 0700 );
return dir.path() + "/" + "Categories" + ".xml";
}
void CategoryEdit::kludge()
{
lvView->setMaximumHeight( 130 );
}
diff --git a/library/categorymenu.cpp b/library/categorymenu.cpp
index 5d7adf7..9bbb448 100644
--- a/library/categorymenu.cpp
+++ b/library/categorymenu.cpp
@@ -1,162 +1,160 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of 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 "categorymenu.h"
#include "backend/categories.h"
#include "categoryselect.h"
-#include <qstring.h>
-#include <qmap.h>
/*!
\class CategoryMenu
\brief The CategoryMenu widget aids in filtering records or files by Category.
The CategoryMenu widget provides a popup menu that will make filtering records
or files by category much easier. The widget will lookup the available
categories for an application, populate the menu, and keep a track of which
categories are being filtered against. A set of categories can be tested
by the isSelected() function to see if a record or file containing those
categories would be allowed through by the filter.
\warning Currently this class is not suitable for extending.
\ingroup qtopiaemb
*/
/*!
\fn void CategoryMenu::categoryChange()
This signal is emitted when the user selects a different category in the
menu, hence changing what records or files should be selected.
*/
/*!
Creates a new CategoryMenu with \a parent and \a name. The menu will be
populated with the available categories for \a application.
If \a globals is TRUE then it will also poplulate the menu with the
global categories.
*/
CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE,
QWidget *parent, const char *name ) :
QPopupMenu(parent, name),
appName(n),
includeGlobal(ig)
{
currentMid = 1;
reload();
connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int)));
}
/*!
Destroys a CategoryMenu.
*/
CategoryMenu::~CategoryMenu( )
{
}
/*!
Repopulates the widget's list of available categories.
*/
void CategoryMenu::reload()
{
clear();
Categories c;
c.load(categoryFileName());
QStringList sl = c.labels(appName, includeGlobal);
int mid = 1;
insertItem(tr("All"), mid);
mid++;
insertItem(tr("Unfiled"), mid);
mid++;
for (QStringList::Iterator it = sl.begin();
it != sl.end(); ++it ) {
int cid = c.id(appName, *it);
insertItem(*it, mid);
menuToId.insert(mid, cid);
idToMenu.insert(cid, mid);
mid++;
}
setItemChecked(currentMid, TRUE );
}
/*!
\internal
*/
void CategoryMenu::mapMenuId(int id)
{
if (id == currentMid)
return;
setItemChecked( currentMid, FALSE );
setItemChecked( id, TRUE );
currentMid = id;
emit categoryChange();
}
/*!
Returns TRUE if a record or file with the set of category ids \a cUids
is allowed by the current selection in the CategoryMenu.
Otherwise returns FALSE.
*/
bool CategoryMenu::isSelected(const QArray<int> &cUids) const
{
if (currentMid == 1)
return TRUE;
if (currentMid == 2 && cUids.count() == 0)
return TRUE;
if (cUids.contains(menuToId[currentMid]))
return TRUE;
return FALSE;
}
/*!
Sets the menu to have \a newCatUid as the currently selected Category.
*/
void CategoryMenu::setCurrentCategory( int newCatUid )
{
if (!idToMenu.contains(newCatUid))
return;
mapMenuId(idToMenu[newCatUid]);
}
/*!
Sets the menu to allow all category sets.
*/
void CategoryMenu::setCurrentCategoryAll( )
{
mapMenuId(1);
}
/*!
Sets the menu to allow only empty category sets.
*/
void CategoryMenu::setCurrentCategoryUnfiled( )
{
mapMenuId(2);
}
diff --git a/library/config.cpp b/library/config.cpp
index b28c771..8b60f60 100644
--- a/library/config.cpp
+++ b/library/config.cpp
@@ -1,580 +1,578 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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 <qfileinfo.h>
#include <qmessagebox.h>
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
#include <qtextcodec.h>
#endif
#include <qtextstream.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#define QTOPIA_INTERNAL_LANGLIST
#include "config.h"
#include "global.h"
/*!
\internal
*/
QString Config::configFilename(const QString& name, Domain d)
{
switch (d) {
case File:
return name;
case User: {
QDir dir = (QString(getenv("HOME")) + "/Settings");
if ( !dir.exists() )
mkdir(dir.path().local8Bit(),0700);
return dir.path() + "/" + name + ".conf";
}
}
return name;
}
/*!
\class Config config.h
\brief The Config class provides for saving application cofniguration state.
You should keep a Config in existence only while you do not want others
to be able to change the state. There is no locking currently, but there
may be in the future.
*/
/*!
\enum Config::ConfigGroup
\internal
*/
/*!
\enum Config::Domain
\value File
\value User
See Config for details.
*/
/*!
Constructs a config that will load or create a configuration with the
given \a name in the given \a domain.
You must call setGroup() before doing much else with the Config.
In the default Domain, \e User,
the configuration is user-specific. \a name should not contain "/" in
this case, and in general should be the name of the C++ class that is
primarily responsible for maintaining the configuration.
In the File Domain, \a name is an absolute filename.
*/
Config::Config( const QString &name, Domain domain )
: filename( configFilename(name,domain) )
{
git = groups.end();
read();
QStringList l = Global::languageList();
lang = l[0];
glang = l[1];
}
// Sharp ROM compatibility
Config::Config ( const QString &name, bool what )
: filename( configFilename(name,what ? User : File) )
{
git = groups.end();
read();
QStringList l = Global::languageList();
lang = l[0];
glang = l[1];
}
/*!
Writes any changes to disk and destroys the in-memory object.
*/
Config::~Config()
{
if ( changed )
write();
}
/*!
Returns whether the current group has an entry called \a key.
*/
bool Config::hasKey( const QString &key ) const
{
if ( groups.end() == git )
return FALSE;
ConfigGroup::ConstIterator it = ( *git ).find( key );
return it != ( *git ).end();
}
/*!
Sets the current group for subsequent reading and writing of
entries to \a gname. Grouping allows the application to partition the namespace.
This function must be called prior to any reading or writing
of entries.
The \a gname must not be empty.
*/
void Config::setGroup( const QString &gname )
{
QMap< QString, ConfigGroup>::Iterator it = groups.find( gname );
if ( it == groups.end() ) {
git = groups.insert( gname, ConfigGroup() );
changed = TRUE;
return;
}
git = it;
}
/*!
Writes a (\a key, \a value) entry to the current group.
\sa readEntry()
*/
void Config::writeEntry( const QString &key, const char* value )
{
writeEntry(key,QString(value));
}
/*!
Writes a (\a key, \a value) entry to the current group.
\sa readEntry()
*/
void Config::writeEntry( const QString &key, const QString &value )
{
if ( git == groups.end() ) {
qWarning( "no group set" );
return;
}
if ( (*git)[key] != value ) {
( *git ).insert( key, value );
changed = TRUE;
}
}
/*
Note that the degree of protection offered by the encryption here is
only sufficient to avoid the most casual observation of the configuration
files. People with access to the files can write down the contents and
decrypt it using this source code.
Conceivably, and at some burden to the user, this encryption could
be improved.
*/
static QString encipher(const QString& plain)
{
// mainly, we make it long
QString cipher;
int mix=28730492;
for (int i=0; i<(int)plain.length(); i++) {
int u = plain[i].unicode();
int c = u ^ mix;
QString x = QString::number(c,36);
cipher.append(QChar('a'+x.length()));
cipher.append(x);
mix *= u;
}
return cipher;
}
static QString decipher(const QString& cipher)
{
QString plain;
int mix=28730492;
for (int i=0; i<(int)cipher.length();) {
int l = cipher[i].unicode()-'a';
QString x = cipher.mid(i+1,l); i+=l+1;
int u = x.toInt(0,36) ^ mix;
plain.append(QChar(u));
mix *= u;
}
return plain;
}
/*!
Writes an encrypted (\a key, \a value) entry to the current group.
Note that the degree of protection offered by the encryption is
only sufficient to avoid the most casual observation of the configuration
files.
\sa readEntry()
*/
void Config::writeEntryCrypt( const QString &key, const QString &value )
{
if ( git == groups.end() ) {
qWarning( "no group set" );
return;
}
QString evalue = encipher(value);
if ( (*git)[key] != evalue ) {
( *git ).insert( key, evalue );
changed = TRUE;
}
}
/*!
Writes a (\a key, \a num) entry to the current group.
\sa readNumEntry()
*/
void Config::writeEntry( const QString &key, int num )
{
QString s;
s.setNum( num );
writeEntry( key, s );
}
#ifdef Q_HAS_BOOL_TYPE
/*!
Writes a (\a key, \a b) entry to the current group. This is equivalent
to writing a 0 or 1 as an integer entry.
\sa readBoolEntry()
*/
void Config::writeEntry( const QString &key, bool b )
{
QString s;
s.setNum( ( int )b );
writeEntry( key, s );
}
#endif
/*!
Writes a (\a key, \a lst) entry to the current group. The list
is separated by \a sep, so the strings must not contain that character.
\sa readListEntry()
*/
void Config::writeEntry( const QString &key, const QStringList &lst, const QChar &sep )
{
QString s;
QStringList::ConstIterator it = lst.begin();
for ( ; it != lst.end(); ++it )
s += *it + sep;
writeEntry( key, s );
}
/*!
Removes the \a key entry from the current group. Does nothing if
there is no such entry.
*/
void Config::removeEntry( const QString &key )
{
if ( git == groups.end() ) {
qWarning( "no group set" );
return;
}
( *git ).remove( key );
changed = TRUE;
}
/*!
\fn bool Config::operator == ( const Config & other ) const
Tests for equality with \a other. Config objects are equal if they refer to the same filename.
*/
/*!
\fn bool Config::operator != ( const Config & other ) const
Tests for inequality with \a other. Config objects are equal if they refer to the same filename.
*/
/*!
\fn QString Config::readEntry( const QString &key, const QString &deflt ) const
Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry.
*/
/*!
\internal
For compatibility, non-const version.
*/
QString Config::readEntry( const QString &key, const QString &deflt )
{
QString res = readEntryDirect( key+"["+lang+"]" );
if ( !res.isNull() )
return res;
if ( !glang.isEmpty() ) {
res = readEntryDirect( key+"["+glang+"]" );
if ( !res.isNull() )
return res;
}
return readEntryDirect( key, deflt );
}
/*!
\fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const
Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry.
*/
/*!
\internal
For compatibility, non-const version.
*/
QString Config::readEntryCrypt( const QString &key, const QString &deflt )
{
QString res = readEntryDirect( key+"["+lang+"]" );
if ( res.isNull() && glang.isEmpty() )
res = readEntryDirect( key+"["+glang+"]" );
if ( res.isNull() )
res = readEntryDirect( key, QString::null );
if ( res.isNull() )
return deflt;
return decipher(res);
}
/*!
\fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const
\internal
*/
/*!
\internal
For compatibility, non-const version.
*/
QString Config::readEntryDirect( const QString &key, const QString &deflt )
{
if ( git == groups.end() ) {
//qWarning( "no group set" );
return deflt;
}
ConfigGroup::ConstIterator it = ( *git ).find( key );
if ( it != ( *git ).end() )
return *it;
else
return deflt;
}
/*!
\fn int Config::readNumEntry( const QString &key, int deflt ) const
Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry.
*/
/*!
\internal
For compatibility, non-const version.
*/
int Config::readNumEntry( const QString &key, int deflt )
{
QString s = readEntry( key );
if ( s.isEmpty() )
return deflt;
else
return s.toInt();
}
/*!
\fn bool Config::readBoolEntry( const QString &key, bool deflt ) const
Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry.
*/
/*!
\internal
For compatibility, non-const version.
*/
bool Config::readBoolEntry( const QString &key, bool deflt )
{
QString s = readEntry( key );
if ( s.isEmpty() )
return deflt;
else
return (bool)s.toInt();
}
/*!
\fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const
Reads a string list entry stored with \a key, and with \a sep as the separator.
*/
/*!
\internal
For compatibility, non-const version.
*/
QStringList Config::readListEntry( const QString &key, const QChar &sep )
{
QString s = readEntry( key );
if ( s.isEmpty() )
return QStringList();
else
return QStringList::split( sep, s );
}
/*!
Removes all entries from the current group.
*/
void Config::clearGroup()
{
if ( git == groups.end() ) {
qWarning( "no group set" );
return;
}
if ( !(*git).isEmpty() ) {
( *git ).clear();
changed = TRUE;
}
}
/*!
\internal
*/
void Config::write( const QString &fn )
{
QString strNewFile;
if ( !fn.isEmpty() )
filename = fn;
strNewFile = filename + ".new";
QFile f( strNewFile );
if ( !f.open( IO_WriteOnly|IO_Raw ) ) {
qWarning( "could not open for writing `%s'", strNewFile.latin1() );
git = groups.end();
return;
}
QString str;
QCString cstr;
QMap< QString, ConfigGroup >::Iterator g_it = groups.begin();
for ( ; g_it != groups.end(); ++g_it ) {
str += "[" + g_it.key() + "]\n";
ConfigGroup::Iterator e_it = ( *g_it ).begin();
for ( ; e_it != ( *g_it ).end(); ++e_it )
str += e_it.key() + " = " + *e_it + "\n";
}
cstr = str.utf8();
int total_length;
total_length = f.writeBlock( cstr.data(), cstr.length() );
if ( total_length != int(cstr.length()) ) {
QMessageBox::critical( 0, QObject::tr("Out of Space"),
QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") );
f.close();
QFile::remove( strNewFile );
return;
}
f.close();
// now rename the file...
if ( rename( strNewFile, filename ) < 0 ) {
qWarning( "problem renaming the file %s to %s", strNewFile.latin1(),
filename.latin1() );
QFile::remove( strNewFile );
}
}
/*!
Returns whether the Config is in a valid state.
*/
bool Config::isValid() const
{
return groups.end() != git;
}
/*!
\internal
*/
void Config::read()
{
changed = FALSE;
if ( !QFileInfo( filename ).exists() ) {
git = groups.end();
return;
}
QFile f( filename );
if ( !f.open( IO_ReadOnly ) ) {
git = groups.end();
return;
}
// hack to avoid problems if big files are passed to test
// if they are valid configs ( like passing a mp3 ... )
// I just hope that there are no conf files > 100000 byte
// not the best solution, find something else later
if ( f.size() > 100000 ) {
return;
}
QTextStream s( &f );
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
// The below should work, but doesn't in Qt 2.3.0
s.setCodec( QTextCodec::codecForMib( 106 ) );
#else
s.setEncoding( QTextStream::UnicodeUTF8 );
#endif
QStringList list = QStringList::split('\n', s.read() );
f.close();
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
if ( !parse( *it ) ) {
git = groups.end();
return;
}
}
}
/*!
\internal
*/
bool Config::parse( const QString &l )
{
QString line = l.stripWhiteSpace();
if ( line [0] == QChar ( '#' ))
return true; // ignore comments
if ( line[ 0 ] == QChar( '[' ) ) {
QString gname = line;
gname = gname.remove( 0, 1 );
if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) )
gname = gname.remove( gname.length() - 1, 1 );
git = groups.insert( gname, ConfigGroup() );
} else if ( !line.isEmpty() ) {
if ( git == groups.end() )
return FALSE;
int eq = line.find( '=' );
if ( eq == -1 )
return FALSE;
QString key = line.left(eq).stripWhiteSpace();
QString value = line.mid(eq+1).stripWhiteSpace();
( *git ).insert( key, value );
}
return TRUE;
}
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index 188d8e1..e4ec2bf 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -1,1146 +1,1141 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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 <qasciidict.h>
-#include <qfile.h>
#include <qmessagebox.h>
-#include <qstring.h>
-#include <qtextcodec.h>
-#include <qtextstream.h>
#include <qtl.h>
#include <qpe/alarmserver.h>
#include <qpe/global.h>
#include "datebookdb.h"
#include <qpe/stringutil.h>
-#include <qpe/timeconversion.h>
#include <errno.h>
#include <stdlib.h>
class DateBookDBPrivate
{
public:
bool clean; // indcate whether we need to write to disk...
};
// Helper functions
static QString dateBookJournalFile()
{
QString str = getenv("HOME");
return QString( str +"/.caljournal" );
}
static QString dateBookFilename()
{
return Global::applicationFileName("datebook","datebook.xml");
}
/* Calculating the next event of a recuring event is actually
computationally inexpensive, esp. compared to checking each day
individually. There are bad worse cases for say the 29th of
february or the 31st of some other months. However
these are still bounded */
bool nextOccurance(const Event &e, const QDate &from, QDateTime &next)
{
// easy checks, first are we too far in the future or too far in the past?
QDate tmpDate;
int freq = e.repeatPattern().frequency;
int diff, diff2, a;
int iday, imonth, iyear;
int dayOfWeek = 0;
int firstOfWeek = 0;
int weekOfMonth;
if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from)
return FALSE;
if (e.start() >= from) {
next = e.start();
return TRUE;
}
switch ( e.repeatPattern().type ) {
case Event::Weekly:
/* weekly is just daily by 7 */
/* first convert the repeatPattern.Days() mask to the next
day of week valid after from */
dayOfWeek = from.dayOfWeek();
dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */
/* this is done in case freq > 1 and from in week not
for this round */
// firstOfWeek = 0; this is already done at decl.
while(!((1 << firstOfWeek) & e.repeatPattern().days))
firstOfWeek++;
/* there is at least one 'day', or there would be no event */
while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days))
dayOfWeek++;
dayOfWeek = dayOfWeek % 7; /* the actual day of week */
dayOfWeek -= e.start().date().dayOfWeek() -1;
firstOfWeek = firstOfWeek % 7; /* the actual first of week */
firstOfWeek -= e.start().date().dayOfWeek() -1;
// dayOfWeek may be negitive now
// day of week is number of days to add to start day
freq *= 7;
// FALL-THROUGH !!!!!
case Event::Daily:
// the add is for the possible fall through from weekly */
if(e.start().date().addDays(dayOfWeek) > from) {
/* first week exception */
next = QDateTime(e.start().date().addDays(dayOfWeek),
e.start().time());
if ((next.date() > e.repeatPattern().endDate())
&& e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
}
/* if from is middle of a non-week */
diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq;
diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq;
if(diff != 0)
diff = freq - diff;
if(diff2 != 0)
diff2 = freq - diff2;
diff = QMIN(diff, diff2);
next = QDateTime(from.addDays(diff), e.start().time());
if ( (next.date() > e.repeatPattern().endDate())
&& e.repeatPattern().hasEndDate )
return FALSE;
return TRUE;
case Event::MonthlyDay:
iday = from.day();
iyear = from.year();
imonth = from.month();
/* find equivelent day of month for this month */
dayOfWeek = e.start().date().dayOfWeek();
weekOfMonth = (e.start().date().day() - 1) / 7;
/* work out when the next valid month is */
a = from.year() - e.start().date().year();
a *= 12;
a = a + (imonth - e.start().date().month());
/* a is e.start()monthsFrom(from); */
if(a % freq) {
a = freq - (a % freq);
imonth = from.month() + a;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
}
/* imonth is now the first month after or on
from that matches the frequency given */
/* find for this month */
tmpDate = QDate( iyear, imonth, 1 );
iday = 1;
iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
iday += 7 * weekOfMonth;
while (iday > tmpDate.daysInMonth()) {
imonth += freq;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
tmpDate = QDate( iyear, imonth, 1 );
/* these loops could go for a while, check end case now */
if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
iday = 1;
iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
iday += 7 * weekOfMonth;
}
tmpDate = QDate(iyear, imonth, iday);
if (tmpDate >= from) {
next = QDateTime(tmpDate, e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
}
/* need to find the next iteration */
do {
imonth += freq;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
tmpDate = QDate( iyear, imonth, 1 );
/* these loops could go for a while, check end case now */
if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
iday = 1;
iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
iday += 7 * weekOfMonth;
} while (iday > tmpDate.daysInMonth());
tmpDate = QDate(iyear, imonth, iday);
next = QDateTime(tmpDate, e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
case Event::MonthlyDate:
iday = e.start().date().day();
iyear = from.year();
imonth = from.month();
a = from.year() - e.start().date().year();
a *= 12;
a = a + (imonth - e.start().date().month());
/* a is e.start()monthsFrom(from); */
if(a % freq) {
a = freq - (a % freq);
imonth = from.month() + a;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
}
/* imonth is now the first month after or on
from that matches the frequencey given */
/* this could go for a while, worse case, 4*12 iterations, probably */
while(!QDate::isValid(iyear, imonth, iday) ) {
imonth += freq;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
/* these loops could go for a while, check end case now */
if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
}
if(QDate(iyear, imonth, iday) >= from) {
/* done */
next = QDateTime(QDate(iyear, imonth, iday),
e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
}
/* ok, need to cycle */
imonth += freq;
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
while(!QDate::isValid(iyear, imonth, iday) ) {
imonth += freq;
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
}
next = QDateTime(QDate(iyear, imonth, iday), e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
case Event::Yearly:
iday = e.start().date().day();
imonth = e.start().date().month();
iyear = from.year(); // after all, we want to start in this year
diff = 1;
if(imonth == 2 && iday > 28) {
/* leap year, and it counts, calculate actual frequency */
if(freq % 4)
if (freq % 2)
freq = freq * 4;
else
freq = freq * 2;
/* else divides by 4 already, leave freq alone */
diff = 4;
}
a = from.year() - e.start().date().year();
if(a % freq) {
a = freq - (a % freq);
iyear = iyear + a;
}
/* under the assumption we won't hit one of the special not-leap years twice */
if(!QDate::isValid(iyear, imonth, iday)) {
/* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
iyear += freq;
}
if(QDate(iyear, imonth, iday) >= from) {
next = QDateTime(QDate(iyear, imonth, iday),
e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
}
/* iyear == from.year(), need to advance again */
iyear += freq;
/* under the assumption we won't hit one of the special not-leap years twice */
if(!QDate::isValid(iyear, imonth, iday)) {
/* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
iyear += freq;
}
next = QDateTime(QDate(iyear, imonth, iday), e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
default:
return FALSE;
}
}
static bool nextAlarm( const Event &ev, QDateTime& when, int& warn)
{
QDateTime now = QDateTime::currentDateTime();
if ( ev.hasRepeat() ) {
QDateTime ralarm;
if (nextOccurance(ev, now.date(), ralarm)) {
ralarm = ralarm.addSecs(-ev.alarmTime()*60);
if ( ralarm > now ) {
when = ralarm;
warn = ev.alarmTime();
} else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) {
ralarm = ralarm.addSecs( -ev.alarmTime()*60 );
if ( ralarm > now ) {
when = ralarm;
warn = ev.alarmTime();
}
}
}
} else {
warn = ev.alarmTime();
when = ev.start().addSecs( -ev.alarmTime()*60 );
}
return when > now;
}
static void addEventAlarm( const Event &ev )
{
QDateTime when;
int warn;
if ( nextAlarm(ev,when,warn) )
AlarmServer::addAlarm( when,
"QPE/Application/datebook",
"alarm(QDateTime,int)", warn );
}
static void delEventAlarm( const Event &ev )
{
QDateTime when;
int warn;
if ( nextAlarm(ev,when,warn) )
AlarmServer::deleteAlarm( when,
"QPE/Application/datebook",
"alarm(QDateTime,int)", warn );
}
DateBookDB::DateBookDB()
{
init();
}
DateBookDB::~DateBookDB()
{
save();
eventList.clear();
repeatEvents.clear();
}
//#### Why is this code duplicated in getEffectiveEvents ?????
//#### Addendum. Don't use this function, lets faze it out if we can.
QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to )
{
QValueList<Event> tmpList;
tmpList = getNonRepeatingEvents( from, to );
// check for repeating events...
for (QValueList<Event>::ConstIterator it = repeatEvents.begin();
it != repeatEvents.end(); ++it) {
QDate itDate = from;
QDateTime due;
/* create a false end date, to short circuit on hard
MonthlyDay recurences */
Event dummy_event = *it;
Event::RepeatPattern r = dummy_event.repeatPattern();
if ( !r.hasEndDate || r.endDate() > to ) {
r.setEndDate( to );
r.hasEndDate = TRUE;
}
dummy_event.setRepeat(TRUE, r);
while (nextOccurance(dummy_event, itDate, due)) {
if (due.date() > to)
break;
Event newEvent = *it;
newEvent.setStart(due);
newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end())));
tmpList.append(newEvent);
itDate = due.date().addDays(1); /* the next event */
}
}
qHeapSort(tmpList);
return tmpList;
}
QValueList<Event> DateBookDB::getEvents( const QDateTime &start )
{
QValueList<Event> day = getEvents(start.date(),start.date());
QValueListConstIterator<Event> it;
QDateTime dtTmp;
QValueList<Event> tmpList;
for (it = day.begin(); it != day.end(); ++it ) {
dtTmp = (*it).start(TRUE);
if ( dtTmp == start )
tmpList.append( *it );
}
return tmpList;
}
//#### Why is this code duplicated in getEvents ?????
QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from,
const QDate &to )
{
QValueList<EffectiveEvent> tmpList;
QValueListIterator<Event> it;
EffectiveEvent effEv;
QDateTime dtTmp,
dtEnd;
for (it = eventList.begin(); it != eventList.end(); ++it ) {
if (!(*it).isValidUid())
(*it).assignUid(); // FIXME: Hack to restore cleared uids
dtTmp = (*it).start(TRUE);
dtEnd = (*it).end(TRUE);
if ( dtTmp.date() >= from && dtTmp.date() <= to ) {
Event tmpEv = *it;
effEv.setEvent(tmpEv);
effEv.setDate( dtTmp.date() );
effEv.setStart( dtTmp.time() );
if ( dtTmp.date() != dtEnd.date() )
effEv.setEnd( QTime(23, 59, 0) );
else
effEv.setEnd( dtEnd.time() );
tmpList.append( effEv );
}
// we must also check for end date information...
if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) {
QDateTime dt = dtTmp.addDays( 1 );
dt.setTime( QTime(0, 0, 0) );
QDateTime dtStop;
if ( dtEnd > to ) {
dtStop = to;
} else
dtStop = dtEnd;
while ( dt <= dtStop ) {
Event tmpEv = *it;
effEv.setEvent( tmpEv );
effEv.setDate( dt.date() );
if ( dt >= from ) {
effEv.setStart( QTime(0, 0, 0) );
if ( dt.date() == dtEnd.date() )
effEv.setEnd( dtEnd.time() );
else
effEv.setEnd( QTime(23, 59, 59) );
tmpList.append( effEv );
}
dt = dt.addDays( 1 );
}
}
}
// check for repeating events...
QDateTime repeat;
for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) {
if (!(*it).isValidUid())
(*it).assignUid(); // FIXME: Hack to restore cleared uids
/* create a false end date, to short circuit on hard
MonthlyDay recurences */
Event dummy_event = *it;
int duration = (*it).start().date().daysTo( (*it).end().date() );
QDate itDate = from.addDays(-duration);
Event::RepeatPattern r = dummy_event.repeatPattern();
if ( !r.hasEndDate || r.endDate() > to ) {
r.setEndDate( to );
r.hasEndDate = TRUE;
}
dummy_event.setRepeat(TRUE, r);
while (nextOccurance(dummy_event, itDate, repeat)) {
if(repeat.date() > to)
break;
effEv.setDate( repeat.date() );
if ((*it).type() == Event::AllDay) {
effEv.setStart( QTime(0,0,0) );
effEv.setEnd( QTime(23,59,59) );
} else {
/* we only occur by days, not hours/minutes/seconds. Hence
the actual end and start times will be the same for
every repeated event. For multi day events this is
fixed up later if on wronge day span */
effEv.setStart( (*it).start().time() );
effEv.setEnd( (*it).end().time() );
}
if ( duration != 0 ) {
// multi-day repeating events
QDate sub_it = QMAX( repeat.date(), from );
QDate startDate = repeat.date();
QDate endDate = startDate.addDays( duration );
while ( sub_it <= endDate && sub_it <= to ) {
EffectiveEvent tmpEffEv = effEv;
Event tmpEv = *it;
tmpEffEv.setEvent( tmpEv );
if ( sub_it != startDate )
tmpEffEv.setStart( QTime(0,0,0) );
if ( sub_it != endDate )
tmpEffEv.setEnd( QTime(23,59,59) );
tmpEffEv.setDate( sub_it );
tmpEffEv.setEffectiveDates( startDate, endDate );
tmpList.append( tmpEffEv );
sub_it = sub_it.addDays( 1 );
}
itDate = endDate;
} else {
Event tmpEv = *it;
effEv.setEvent( tmpEv );
tmpList.append( effEv );
itDate = repeat.date().addDays( 1 );
}
}
}
qHeapSort( tmpList );
return tmpList;
}
QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt)
{
QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date());
QValueListConstIterator<EffectiveEvent> it;
QValueList<EffectiveEvent> tmpList;
QDateTime dtTmp;
for (it = day.begin(); it != day.end(); ++it ) {
dtTmp = QDateTime( (*it).date(), (*it).start() );
// at the moment we don't have second granularity, be nice about that..
if ( QABS(dt.secsTo(dtTmp)) < 60 )
tmpList.append( *it );
}
return tmpList;
}
void DateBookDB::addEvent( const Event &ev, bool doalarm )
{
// write to the journal...
saveJournalEntry( ev, ACTION_ADD, -1, false );
addJFEvent( ev, doalarm );
d->clean = false;
}
void DateBookDB::addJFEvent( const Event &ev, bool doalarm )
{
if ( doalarm && ev.hasAlarm() )
addEventAlarm( ev );
if ( ev.hasRepeat() )
repeatEvents.append( ev );
else
eventList.append( ev );
}
void DateBookDB::editEvent( const Event &old, Event &editedEv )
{
int oldIndex=0;
bool oldHadRepeat = old.hasRepeat();
Event orig;
// write to the journal...
if ( oldHadRepeat ) {
if ( origRepeat( old, orig ) ) // should work always...
oldIndex = repeatEvents.findIndex( orig );
} else
oldIndex = eventList.findIndex( old );
saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat );
// Delete old event
if ( old.hasAlarm() )
delEventAlarm( old );
if ( oldHadRepeat ) {
if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and
// orig is initialized
// assumption, when someone edits a repeating event, they
// want to change them all, maybe not perfect, but it works
// for the moment...
repeatEvents.remove( orig );
} else
removeRepeat( old );
} else {
QValueList<Event>::Iterator it = eventList.find( old );
if ( it != eventList.end() )
eventList.remove( it );
}
// Add new event
if ( editedEv.hasAlarm() )
addEventAlarm( editedEv );
if ( editedEv.hasRepeat() )
repeatEvents.append( editedEv );
else
eventList.append( editedEv );
d->clean = false;
}
void DateBookDB::removeEvent( const Event &ev )
{
// write to the journal...
saveJournalEntry( ev, ACTION_REMOVE, -1, false );
removeJFEvent( ev );
d->clean = false;
}
void DateBookDB::removeJFEvent( const Event&ev )
{
if ( ev.hasAlarm() )
delEventAlarm( ev );
if ( ev.hasRepeat() ) {
removeRepeat( ev );
} else {
QValueList<Event>::Iterator it = eventList.find( ev );
if ( it != eventList.end() )
eventList.remove( it );
}
}
// also handles journaling...
void DateBookDB::loadFile( const QString &strFile )
{
QFile f( strFile );
if ( !f.open( IO_ReadOnly ) )
return;
enum Attribute {
FDescription = 0,
FLocation,
FCategories,
FUid,
FType,
FAlarm,
FSound,
FRType,
FRWeekdays,
FRPosition,
FRFreq,
FRHasEndDate,
FREndDate,
FRStart,
FREnd,
FNote,
FCreated,
FAction,
FActionKey,
FJournalOrigHadRepeat
};
QAsciiDict<int> dict( 97 );
dict.setAutoDelete( TRUE );
dict.insert( "description", new int(FDescription) );
dict.insert( "location", new int(FLocation) );
dict.insert( "categories", new int(FCategories) );
dict.insert( "uid", new int(FUid) );
dict.insert( "type", new int(FType) );
dict.insert( "alarm", new int(FAlarm) );
dict.insert( "sound", new int(FSound) );
dict.insert( "rtype", new int(FRType) );
dict.insert( "rweekdays", new int(FRWeekdays) );
dict.insert( "rposition", new int(FRPosition) );
dict.insert( "rfreq", new int(FRFreq) );
dict.insert( "rhasenddate", new int(FRHasEndDate) );
dict.insert( "enddt", new int(FREndDate) );
dict.insert( "start", new int(FRStart) );
dict.insert( "end", new int(FREnd) );
dict.insert( "note", new int(FNote) );
dict.insert( "created", new int(FCreated) );
dict.insert( "action", new int(FAction) );
dict.insert( "actionkey", new int(FActionKey) );
dict.insert( "actionorig", new int (FJournalOrigHadRepeat) );
QByteArray ba = f.readAll();
char* dt = ba.data();
int len = ba.size();
int currentAction,
journalKey,
origHadRepeat; // should be bool, but we need tri-state(not being used)
int i = 0;
char *point;
// hack to get rid of segfaults after reading </DATEBOOK>
while ( (dt+i != 0) && (( point = strstr( dt+i, "<event " ) ) != 0 )) {
i = point - dt;
// if we are reading in events in the general case,
// we are just adding them, so let the actions represent that...
currentAction = ACTION_ADD;
journalKey = -1;
origHadRepeat = -1;
// some temporary variables for dates and times ...
//int startY = 0, startM = 0, startD = 0, starth = 0, startm = 0, starts = 0;
//int endY = 0, endM = 0, endD = 0, endh = 0, endm = 0, ends = 0;
//int enddtY = 0, enddtM = 0, enddtD = 0;
// ... for the alarm settings ...
int alarmTime = -1; Event::SoundTypeChoice alarmSound = Event::Silent;
// ... and for the recurrence
Event::RepeatPattern rp;
Event e;
i += 7;
while( 1 ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
break;
// we have another attribute, read it.
int j = i;
while ( j < len && dt[j] != '=' )
++j;
char *attr = dt+i;
dt[j] = '\0';
i = ++j; // skip =
while ( i < len && dt[i] != '"' )
++i;
j = ++i;
bool haveAmp = FALSE;
bool haveUtf = FALSE;
while ( j < len && dt[j] != '"' ) {
if ( dt[j] == '&' )
haveAmp = TRUE;
if ( ((unsigned char)dt[j]) > 0x7f )
haveUtf = TRUE;
++j;
}
if ( i == j ) {
// leave out empty attributes
i = j + 1;
continue;
}
QString value = haveUtf ? QString::fromUtf8( dt+i, j-i )
: QString::fromLatin1( dt+i, j-i );
if ( haveAmp )
value = Qtopia::plainString( value );
i = j + 1;
//qDebug("attr='%s' value='%s'", attr.data(), value.latin1() );
int * find = dict[ attr ];
#if 1
if ( !find ) {
// custom field
e.setCustomField(attr, value);
continue;
}
switch( *find ) {
case FDescription:
e.setDescription( value );
break;
case FLocation:
e.setLocation( value );
break;
case FCategories:
e.setCategories( Qtopia::Record::idsFromString( value ) );
break;
case FUid:
e.setUid( value.toInt() );
break;
case FType:
if ( value == "AllDay" )
e.setType( Event::AllDay );
else
e.setType( Event::Normal );
break;
case FAlarm:
alarmTime = value.toInt();
break;
case FSound:
alarmSound = value == "loud" ? Event::Loud : Event::Silent;
break;
// recurrence stuff
case FRType:
if ( value == "Daily" )
rp.type = Event::Daily;
else if ( value == "Weekly" )
rp.type = Event::Weekly;
else if ( value == "MonthlyDay" )
rp.type = Event::MonthlyDay;
else if ( value == "MonthlyDate" )
rp.type = Event::MonthlyDate;
else if ( value == "Yearly" )
rp.type = Event::Yearly;
else
rp.type = Event::NoRepeat;
break;
case FRWeekdays:
// QtopiaDesktop 1.6 sometimes creates 'rweekdays="0"'
// when it goes mad. This causes datebook to crash.. (se)
if ( value.toInt() != 0 )
rp.days = value.toInt();
else
rp.days = 1;
break;
case FRPosition:
rp.position = value.toInt();
break;
case FRFreq:
rp.frequency = value.toInt();
break;
case FRHasEndDate:
rp.hasEndDate = value.toInt();
break;
case FREndDate: {
rp.endDateUTC = (time_t) value.toLong();
break;
}
case FRStart: {
e.setStart( (time_t) value.toLong() );
break;
}
case FREnd: {
e.setEnd( (time_t) value.toLong() );
break;
}
case FNote:
e.setNotes( value );
break;
case FCreated:
rp.createTime = value.toInt();
break;
case FAction:
currentAction = value.toInt();
break;
case FActionKey:
journalKey = value.toInt();
break;
case FJournalOrigHadRepeat:
origHadRepeat = value.toInt();
break;
default:
qDebug( "huh??? missing enum? -- attr.: %s", attr );
break;
}
#endif
}
// "post processing" (dates, times, alarm, recurrence)
// other half of 1169 fixlet without getting into regression
// if rp.days == 0 and rp.type == Event::Weekly
if ( rp.type == Event::Weekly && rp.days == 0 )
rp.days = Event::day( e.start().date().dayOfWeek() );
// start date/time
e.setRepeat( rp.type != Event::NoRepeat, rp );
if ( alarmTime != -1 )
e.setAlarm( TRUE, alarmTime, alarmSound );
// now do our action based on the current action...
switch ( currentAction ) {
case ACTION_ADD:
addJFEvent( e );
break;
case ACTION_REMOVE:
removeJFEvent( e );
break;
case ACTION_REPLACE:
// be a little bit careful,
// in case of a messed up journal...
if ( journalKey > -1 && origHadRepeat > -1 ) {
// get the original from proper list...
if ( origHadRepeat )
removeJFEvent( *(repeatEvents.at(journalKey)) );
else
removeJFEvent( *(eventList.at(journalKey)) );
addJFEvent( e );
}
break;
default:
break;
}
}
f.close();
}
void DateBookDB::init()
{
d = new DateBookDBPrivate;
d->clean = false;
QString str = dateBookFilename();
if ( str.isNull() ) {
QMessageBox::warning( 0, QObject::tr("Out of Space"),
QObject::tr("Unable to create start up files\n"
"Please free up some space\n"
"before entering data") );
}
// continuing along, we call this datebook filename again,
// because they may fix it before continuing, though it seems
// pretty unlikely...
loadFile( dateBookFilename() );
if ( QFile::exists( dateBookJournalFile() ) ) {
// merge the journal
loadFile( dateBookJournalFile() );
// save in our changes and remove the journal...
save();
}
d->clean = true;
}
bool DateBookDB::save()
{
if ( d->clean == true )
return true;
QValueListIterator<Event> it;
int total_written;
QString strFileNew = dateBookFilename() + ".new";
QFile f( strFileNew );
if ( !f.open( IO_WriteOnly|IO_Raw ) )
return FALSE;
QString buf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
buf += "<!DOCTYPE DATEBOOK><DATEBOOK>\n";
buf += "<events>\n";
QCString str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length()) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
for ( it = eventList.begin(); it != eventList.end(); ++it ) {
buf = "<event";
(*it).save( buf );
buf += " />\n";
str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length()) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
}
for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) {
buf = "<event";
(*it).save( buf );
buf += " />\n";
str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length()) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
}
buf = "</events>\n</DATEBOOK>\n";
str = buf.utf8();
total_written = f.writeBlock( str.data(), str.length() );
if ( total_written != int(str.length()) ) {
f.close();
QFile::remove( strFileNew );
return false;
}
f.close();
// now rename... I like to use the systemcall
if ( ::rename( strFileNew, dateBookFilename() ) < 0 ) {
qWarning( "problem renaming file %s to %s errno %d",
strFileNew.latin1(), dateBookFilename().latin1(), errno );
// remove the file, otherwise it will just stick around...
QFile::remove( strFileNew );
}
// may as well remove the journal file...
QFile::remove( dateBookJournalFile() );
d->clean = true;
return true;
}
void DateBookDB::reload()
{
QValueList<Event>::Iterator it = eventList.begin();
for ( ; it != eventList.end(); ++it ) {
if ( (*it).hasAlarm() )
delEventAlarm( *it );
if ( (*it).hasRepeat() )
removeRepeat( *it );
}
eventList.clear();
repeatEvents.clear(); // should be a NOP
init();
}
bool DateBookDB::removeRepeat( const Event &ev )
{
time_t removeMe = ev.repeatPattern().createTime;
QValueListIterator<Event> it;
for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) {
if ( removeMe == (*it).repeatPattern().createTime ) {
(void)repeatEvents.remove( it );
// best break, or we are going into undefined territory!
return TRUE;
}
}
return FALSE;
}
bool DateBookDB::origRepeat( const Event &ev, Event &orig ) const
{
time_t removeMe = ev.repeatPattern().createTime;
QValueListConstIterator<Event> it;
for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) {
if ( removeMe == (*it).repeatPattern().createTime ) {
orig = (*it);
return TRUE;
}
}
return FALSE;
}
void DateBookDB::saveJournalEntry( const Event &ev, journal_action action )
{
saveJournalEntry( ev, action, -1, false );
}
bool DateBookDB::saveJournalEntry( const Event &evOld, journal_action action,
int key, bool origHadRepeat )
{
bool status = false;
Event ev = evOld;
// write our log based on the action
QFile f( dateBookJournalFile() );
if ( !f.open( IO_WriteOnly|IO_Append ) )
return false;
QString buf = "<event";
ev.save( buf );
buf += " action=";
buf += "\"" + QString::number(action) + "\"";
buf += " actionkey=\"" + QString::number(key) + "\"";
buf += " actionorig=\"" + QString::number(origHadRepeat) +"\"";
buf += " />\n";
QString str = buf.utf8();
status = ( f.writeBlock( str.data(), str.length() ) == int(str.length()) );
f.close();
return status;
}
QValueList<Event> DateBookDB::getRawRepeats() const
{
return repeatEvents;
}
QValueList<Event> DateBookDB::getNonRepeatingEvents( const QDate &from,
const QDate &to ) const
{
QValueListConstIterator<Event> it;
QDateTime dtTmp, dtEnd;
QValueList<Event> tmpList;
for (it = eventList.begin(); it != eventList.end(); ++it ) {
dtTmp = (*it).start(TRUE);
dtEnd = (*it).end(TRUE);
if ( dtTmp.date() >= from && dtTmp.date() <= to ) {
Event e = *it;
if ( dtTmp.date() != dtEnd.date() )
e.setEnd( QDateTime(dtTmp.date(), QTime(23, 59, 0)) );
tmpList.append( e );
}
// we must also check for end date information...
if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) {
QDateTime dt = dtTmp.addDays( 1 );
dt.setTime( QTime(0, 0, 0) );
QDateTime dtStop;
if ( dtEnd > to ) {
dtStop = to;
} else
dtStop = dtEnd;
while ( dt <= dtStop ) {
Event ev = *it;
if ( dt >= from ) {
ev.setStart( QDateTime(dt.date(), QTime(0, 0, 0)) );
if ( dt.date() == dtEnd.date() )
ev.setEnd( QDateTime(dt.date(), dtEnd.time()) );
else
ev.setEnd( QDateTime(dt.date(), QTime(23, 59, 0)) );
tmpList.append( ev );
}
dt = dt.addDays( 1 );
}
}
}
return tmpList;
}
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 728045f..76e022f 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,767 +1,762 @@
/**********************************************************************
** 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 "config.h"
#include "datebookmonth.h"
#include "datebookdb.h"
-#include <qtopia/private/event.h>
#include "resource.h"
#include <qpe/qpeapplication.h>
-#include "timestring.h"
#include <qtoolbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
-#include <qdatetime.h>
-#include <qpainter.h>
-#include <qpopupmenu.h>
#include <qvaluestack.h>
#include <qwhatsthis.h>
DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
: QHBox( parent, name )
{
setBackgroundMode( PaletteButton );
begin = new QToolButton( this );
begin->setFocusPolicy(NoFocus);
begin->setPixmap( Resource::loadPixmap( "start" ) );
begin->setAutoRaise( TRUE );
begin->setFixedSize( begin->sizeHint() );
QWhatsThis::add( begin, tr("Show January in the selected year") );
back = new QToolButton( this );
back->setFocusPolicy(NoFocus);
back->setPixmap( Resource::loadPixmap( "back" ) );
back->setAutoRaise( TRUE );
back->setFixedSize( back->sizeHint() );
QWhatsThis::add( back, tr("Show the previous month") );
month = new QComboBox( FALSE, this );
for ( int i = 0; i < 12; ++i )
month->insertItem( Calendar::nameOfMonth( i + 1 ) );
year = new QSpinBox( 1752, 8000, 1, this );
next = new QToolButton( this );
next->setFocusPolicy(NoFocus);
next->setPixmap( Resource::loadPixmap( "forward" ) );
next->setAutoRaise( TRUE );
next->setFixedSize( next->sizeHint() );
QWhatsThis::add( next, tr("Show the next month") );
end = new QToolButton( this );
end->setFocusPolicy(NoFocus);
end->setPixmap( Resource::loadPixmap( "finish" ) );
end->setAutoRaise( TRUE );
end->setFixedSize( end->sizeHint() );
QWhatsThis::add( end, tr("Show December in the selected year") );
connect( month, SIGNAL( activated( int ) ),
this, SLOT( updateDate() ) );
connect( year, SIGNAL( valueChanged( int ) ),
this, SLOT( updateDate() ) );
connect( begin, SIGNAL( clicked() ),
this, SLOT( firstMonth() ) );
connect( end, SIGNAL( clicked() ),
this, SLOT( lastMonth() ) );
connect( back, SIGNAL( clicked() ),
this, SLOT( monthBack() ) );
connect( next, SIGNAL( clicked() ),
this, SLOT( monthForward() ) );
back->setAutoRepeat( TRUE );
next->setAutoRepeat( TRUE );
}
DateBookMonthHeader::~DateBookMonthHeader()
{
}
void DateBookMonthHeader::updateDate()
{
emit dateChanged( year->value(), month->currentItem() + 1 );
}
void DateBookMonthHeader::firstMonth()
{
emit dateChanged( year->value(), 1 );
month->setCurrentItem( 0 );
}
void DateBookMonthHeader::lastMonth()
{
emit dateChanged( year->value(), 12 );
month->setCurrentItem( 11 );
}
void DateBookMonthHeader::monthBack()
{
if ( month->currentItem() > 0 ) {
emit dateChanged( year->value(), month->currentItem() );
month->setCurrentItem( month->currentItem() - 1 );
} else {
emit dateChanged( year->value() - 1, 12 );
// we have a signal set to a changed value in year so we only need to change
// year to get the result...
month->setCurrentItem( 11 );
year->setValue( year->value() - 1 );
}
}
void DateBookMonthHeader::monthForward()
{
if ( month->currentItem() < 11 ) {
emit dateChanged( year->value(), month->currentItem() + 2 );
month->setCurrentItem( month->currentItem() + 1 );
} else {
// we have a signal set to a changed value in year so we only need to change
// year to get the result...
month->setCurrentItem( 0 );
year->setValue( year->value() + 1 );
}
}
void DateBookMonthHeader::setDate( int y, int m )
{
year->setValue( y );
month->setCurrentItem( m - 1 );
}
//---------------------------------------------------------------------------
class DateBookMonthTablePrivate
{
public:
DateBookMonthTablePrivate() {};
~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
QValueList<EffectiveEvent> mMonthEvents;
bool onMonday;
};
DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
DateBookDB *newDb )
: QTable( 6, 7, parent, name ),
db( newDb )
{
d = new DateBookMonthTablePrivate();
selYear = -1;
selMonth = -1;
selDay = -1;
/* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */
year = -1;
month = -1;
day = -1;
Config cfg( "qpe" );
cfg.setGroup( "Time" );
d->onMonday = cfg.readBoolEntry( "MONDAY" );
horizontalHeader()->setResizeEnabled( FALSE );
// we have to do this here... or suffer the consequences later...
for ( int i = 0; i < 7; i++ ){
horizontalHeader()->resizeSection( i, 30 );
setColumnStretchable( i, TRUE );
}
setupLabels();
verticalHeader()->hide();
setLeftMargin( 0 );
for ( int i = 0; i < 6; ++i )
setRowStretchable( i, TRUE );
setSelectionMode( NoSelection );
connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
this, SLOT( dayClicked( int, int ) ) );
connect( this, SIGNAL( currentChanged( int, int ) ),
this, SLOT( dragDay( int, int ) ) );
setVScrollBarMode( AlwaysOff );
setHScrollBarMode( AlwaysOff );
}
DateBookMonthTable::~DateBookMonthTable()
{
monthsEvents.clear();
delete d;
}
void DateBookMonthTable::setDate(int y, int m, int d)
{
if (month == m && year == y) {
if ( selYear == -1 )
year = selYear;
if ( selMonth == -1 )
month = selMonth;
int r1, c1, r2, c2;
findDay(selDay, r1, c1);
selDay = day = d;
findDay(selDay, r2, c2);
setCurrentCell( r2, c2 );
//updateCell(r1,c1);
//updateCell(r2,c2);
} else {
selYear = year = y;
selMonth = month = m;
selDay = day = d;
setupTable();
}
}
void DateBookMonthTable::redraw()
{
setupLabels();
setupTable();
}
void DateBookMonthTable::setWeekStart( bool onMonday )
{
d->onMonday = onMonday;
setupLabels();
setupTable();
}
void DateBookMonthTable::setupTable()
{
QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
QValueList<Calendar::Day>::Iterator it = days.begin();
int row = 0, col = 0;
int crow = 0;
int ccol = 0;
for ( ; it != days.end(); ++it ) {
DayItemMonth *i = (DayItemMonth *)item( row, col );
if ( !i ) {
i = new DayItemMonth( this, QTableItem::Never, "" );
setItem( row, col, i );
}
Calendar::Day calDay = *it;
i->clearEffEvents();
i->setDay( calDay.date );
i->setType( calDay.type );
if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) {
crow = row;
ccol = col;
}
updateCell( row, col );
if ( col == 6 ) {
++row;
col = 0;
} else {
++col;
}
}
setCurrentCell( crow, ccol );
getEvents();
}
void DateBookMonthTable::findDay( int day, int &row, int &col )
{
QDate dtBegin( year, month, 1 );
int skips = dtBegin.dayOfWeek();
int effective_day = day + skips - 1; // row/columns begin at 0
// make an extra adjustment if we start on Mondays.
if ( d->onMonday )
effective_day--;
row = effective_day / 7;
col = effective_day % 7;
}
void DateBookMonthTable::dayClicked( int row, int col )
{
changeDaySelection( row, col );
emit dateClicked( selYear, selMonth, selDay );
}
void DateBookMonthTable::dragDay( int row, int col )
{
changeDaySelection( row, col );
}
void DateBookMonthTable::changeDaySelection( int row, int col )
{
DayItemMonth *i = (DayItemMonth*)item( row, col );
if ( !i )
return;
switch ( i->type() ) {
case Calendar::Day::ThisMonth:
selMonth = month;
break;
case Calendar::Day::PrevMonth:
selMonth = month-1;
break;
default:
selMonth = month+1;
}
selYear = year;
if ( selMonth <= 0 ) {
selMonth = 12;
selYear--;
} else if ( selMonth > 12 ) {
selMonth = 1;
selYear++;
}
selDay = i->day();
}
void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
{
dayClicked( currentRow(), currentColumn() );
}
void DateBookMonthTable::getEvents()
{
if ( !db )
return;
QDate dtStart( year, month, 1 );
d->mMonthEvents = db->getEffectiveEvents( dtStart,
QDate( year, month,
dtStart.daysInMonth() ) );
QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
// now that the events are sorted, basically go through the list, make
// a small list for every day and set it for each item...
// clear all the items...
while ( it != d->mMonthEvents.end() ) {
QValueList<EffectiveEvent> dayEvent;
EffectiveEvent e = *it;
++it;
dayEvent.append( e );
while ( it != d->mMonthEvents.end()
&& e.date() == (*it).date() ) {
dayEvent.append( *it );
++it;
}
int row, col;
findDay( e.date().day(), row, col );
DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
w->setEvents( dayEvent );
updateCell( row, col );
dayEvent.clear();
}
}
void DateBookMonthTable::setupLabels()
{
for ( int i = 0; i < 7; ++i ) {
// horizontalHeader()->resizeSection( i, 30 );
// setColumnStretchable( i, TRUE );
if ( d->onMonday )
horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) );
else {
if ( i == 0 )
horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) );
else
horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) );
}
}
}
//---------------------------------------------------------------------------
DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac,
DateBookDB *data )
: QVBox( parent, name ),
autoClose( ac )
{
setFocusPolicy(StrongFocus);
year = QDate::currentDate().year();
month = QDate::currentDate().month();
day = QDate::currentDate().day();
header = new DateBookMonthHeader( this, "DateBookMonthHeader" );
table = new DateBookMonthTable( this, "DateBookMonthTable", data );
header->setDate( year, month );
table->setDate( year, month, QDate::currentDate().day() );
header->setFocusPolicy(NoFocus);
table->setFocusPolicy(NoFocus);
connect( header, SIGNAL( dateChanged( int, int ) ),
this, SLOT( setDate( int, int ) ) );
connect( table, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( finalDate(int, int, int) ) );
connect( qApp, SIGNAL(weekChanged(bool)), this,
SLOT(slotWeekChange(bool)) );
table->setFocus();
}
DateBookMonth::~DateBookMonth()
{
}
void DateBookMonth::setDate( int y, int m )
{
/* only change the date if this is a different date,
* other wise we may mistakenly overide the day */
if ( (y != year) || (m != month) ) {
year = y;
month = m;
QDate nd( y, m, 1 );
if ( nd.daysInMonth() < day )
day = nd.daysInMonth();
table->setDate( year, month, day );
}
}
void DateBookMonth::setDate( int y, int m, int d )
{
header->setDate( y, m);
table->setDate( y, m, d);
year = y;
month = m;
day = d;
}
/* called when we wish to close or pass back the date */
void DateBookMonth::finalDate(int y, int m, int d)
{
setDate( y, m, d );
emit dateClicked(y, m, d);
// emit dateClicked(QDate(y, m, d).toString());
if ( autoClose && parentWidget() )
parentWidget()->close();
}
void DateBookMonth::setDate( QDate d)
{
setDate(d.year(), d.month(), d.day());
}
void DateBookMonth::redraw()
{
table->setDate( year, month, day );
table->redraw();
}
QDate DateBookMonth::selectedDate() const
{
if ( !table )
return QDate::currentDate();
int y, m, d;
table->getDate( y, m, d );
return QDate( y, m, d );
}
void DateBookMonth::slotWeekChange( bool startOnMonday )
{
table->setWeekStart( startOnMonday );
}
void DateBookMonth::keyPressEvent( QKeyEvent *e )
{
switch(e->key()) {
case Key_Up:
setDate(QDate(year, month, day).addDays(-7));
break;
case Key_Down:
setDate(QDate(year, month, day).addDays(7));
break;
case Key_Left:
setDate(QDate(year, month, day).addDays(-1));
break;
case Key_Right:
setDate(QDate(year, month, day).addDays(1));
break;
case Key_Space:
qWarning("space");
emit dateClicked(year, month, day);
if ( autoClose && parentWidget() )
parentWidget()->close();
break;
default:
qWarning("ignore");
e->ignore();
break;
}
}
//---------------------------------------------------------------------------
class DayItemMonthPrivate
{
public:
DayItemMonthPrivate() {};
~DayItemMonthPrivate() { mDayEvents.clear(); };
QValueList<EffectiveEvent> mDayEvents;
};
DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t )
: QTableItem( table, et, t )
{
d = new DayItemMonthPrivate();
}
DayItemMonth::~DayItemMonth()
{
daysEvents.clear();
delete d;
}
void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv )
{
d->mDayEvents = effEv;
}
void DayItemMonth::clearEffEvents()
{
d->mDayEvents.clear();
}
void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
const QRect &cr, bool selected )
{
p->save();
QColorGroup g( cg );
g.setBrush( QColorGroup::Base, back );
g.setColor( QColorGroup::Text, forg );
if ( selected )
p->setPen( g.highlightedText() );
else
p->setPen( g.text() );
QValueStack<int> normalLine;
QValueStack<int> repeatLine;
QValueStack<int> travelLine;
bool normalAllDay = FALSE;
bool repeatAllDay = FALSE;
bool travelAllDay = FALSE;
QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
int w = cr.width();
Event ev = (*itDays).event();
int f = (*itDays).start().hour(); // assume Effective event
int t = (*itDays).end().hour(); // is truncated.
if (ev.isAllDay()) {
if (!ev.hasRepeat())
normalAllDay = TRUE;
else
repeatAllDay = TRUE;
} else {
int sLine, eLine;
if (f == 0)
sLine = 0;
else if (f < 8 )
sLine = 1;
else if (f >= 17)
sLine = w - 4;
else {
sLine = (f - 8) * (w - 8);
if (sLine)
sLine /= 8;
sLine += 4;
}
if (t == 23)
eLine = w;
else if (t < 8)
eLine = 4;
else if (t >= 17)
eLine = w - 1;
else {
eLine = (t - 8) * (w - 8);
if (eLine)
eLine /= 8;
eLine += 4;
}
if (!ev.hasRepeat()) {
normalLine.push(sLine);
normalLine.push(eLine);
} else {
repeatLine.push(sLine);
repeatLine.push(eLine);
}
}
}
// draw the background
if (normalAllDay || repeatAllDay || travelAllDay) {
p->save();
if (normalAllDay)
if (repeatAllDay) {
p->fillRect( 0, 0, cr.width(), cr.height() / 2,
colorNormalLight );
p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
colorRepeatLight );
} else
p->fillRect( 0, 0, cr.width(), cr.height(),
colorNormalLight );
else if (repeatAllDay)
p->fillRect( 0, 0, cr.width(), cr.height(),
colorRepeatLight );
} else {
p->fillRect( 0, 0, cr.width(),
cr.height(), selected
? g.brush( QColorGroup::Highlight )
: g.brush( QColorGroup::Base ) );
}
// The lines
// now for the lines.
int h = 5;
int y = cr.height() / 2 - h;
while(normalLine.count() >= 2) {
int x2 = normalLine.pop();
int x1 = normalLine.pop();
if (x2 < x1 + 2)
x2 = x1 + 2;
p->fillRect(x1, y, x2 - x1, h, colorNormal);
}
y += h;
while(repeatLine.count() >= 2) {
int x2 = repeatLine.pop();
int x1 = repeatLine.pop();
if (x2 < x1 + 2)
x2 = x1 + 2;
p->fillRect(x1, y, x2 - x1, h, colorRepeat);
}
// Finally, draw the number.
QFont f = p->font();
f.setPointSize( ( f.pointSize() / 3 ) * 2 );
p->setFont( f );
QFontMetrics fm( f );
p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
p->restore();
}
void DayItemMonth::setType( Calendar::Day::Type t )
{
switch ( t ) {
case Calendar::Day::PrevMonth:
case Calendar::Day::NextMonth:
back = QBrush( QColor( 224, 224, 224 ) );
forg = black;
break;
case Calendar::Day::ThisMonth:
back = QBrush( white );
forg = black;
break;
}
typ = t;
}
DateButton::DateButton( bool longDate, QWidget *parent, const char * name )
:QPushButton( parent, name )
{
longFormat = longDate;
df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear);
setDate( QDate::currentDate() );
connect(this,SIGNAL(pressed()),this,SLOT(pickDate()));
}
void DateButton::pickDate()
{
static QPopupMenu *m1 = 0;
static DateBookMonth *picker = 0;
if ( !m1 ) {
m1 = new QPopupMenu( this );
picker = new DateBookMonth( m1, 0, TRUE );
m1->insertItem( picker );
connect( picker, SIGNAL( dateClicked( int, int, int ) ),
this, SLOT( setDate( int, int, int ) ) );
connect( picker, SIGNAL( dateClicked( int, int, int ) ),
this, SIGNAL( dateSelected( int, int, int ) ) );
connect( m1, SIGNAL( aboutToHide() ),
this, SLOT( gotHide() ) );
}
picker->slotWeekChange( weekStartsMonday );
picker->setDate( currDate.year(), currDate.month(), currDate.day() );
m1->popup(mapToGlobal(QPoint(0,height())));
picker->setFocus();
}
void DateButton::gotHide()
{
// we have to redo the button...
setDown( false );
}
// void dateSelected( int year, int month, int day );
void DateButton::setWeekStartsMonday( int b )
{
weekStartsMonday = b;
}
void DateButton::setDate( int y, int m, int d )
{
setDate( QDate( y,m,d) );
}
void DateButton::setDate( QDate d )
{
currDate = d;
setText( longFormat ? TimeString::longDateString( d, df ) :
TimeString::shortDate( d, df ) );
}
void DateButton::setDateFormat( DateFormat f )
{
df = f;
setDate( currDate );
}
bool DateButton::customWhatsThis() const
{
return TRUE;
}
// this class is only here for Sharp ROM compatibility
// I have reverse engineered this class and it seems to
// work (only qtmail seems to use it) - sandman
// DO NOT USE IT IN NEW CODE !!
DateBookMonthPopup::DateBookMonthPopup ( QWidget *w )
: QPopupMenu ( w )
{
m_dbm = new DateBookMonth( this, 0, TRUE );
insertItem( m_dbm );
}
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index 408be20..1e7384e 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -1,443 +1,440 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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 "filemanager.h"
#include "applnk.h"
-#include <qdir.h>
-#include <qfile.h>
#include <qfileinfo.h>
#include <qtextstream.h>
-#include <qtextcodec.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#ifdef Q_OS_MACX
// MacOS X does not have sendfile.. :(
// But maybe in the future.. !?
# ifdef SENDFILE
# include <sys/types.h>
# include <sys/socket.h>
# endif
#else
# include <sys/sendfile.h>
#endif /* Q_OS_MACX */
#include <fcntl.h>
/*!
\class FileManager
\brief The FileManager class assists with AppLnk input/output.
*/
/*!
Constructs a FileManager.
*/
FileManager::FileManager()
{
}
/*!
Destroys a FileManager.
*/
FileManager::~FileManager()
{
}
/*!
Saves \a data as the document specified by \a f.
Returns whether the operation succeeded.
*/
bool FileManager::saveFile( const DocLnk &f, const QByteArray &data )
{
QString fn = f.file() + ".new";
ensurePathExists( fn );
QFile fl( fn );
if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
qWarning("open failed");
return FALSE;
}
int total_written = fl.writeBlock( data );
fl.close();
if ( total_written != int(data.size()) || !f.writeLink() ) {
QFile::remove( fn );
return FALSE;
}
qDebug("total written %d out of %d", total_written, data.size());
// else rename the file...
if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
f.file().latin1(), errno );
// remove the file...
}
return TRUE;
}
/*!
Saves \a text as the document specified by \a f.
The text is saved in UTF8 format.
Returns whether the operation succeeded.
*/
bool FileManager::saveFile( const DocLnk &f, const QString &text )
{
QString fn = f.file() + ".new";
ensurePathExists( fn );
QFile fl( fn );
if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
qWarning("open failed");
return FALSE;
}
QCString cstr = text.utf8();
int total_written;
total_written = fl.writeBlock( cstr.data(), cstr.length() );
fl.close();
if ( total_written != int(cstr.length()) || !f.writeLink() ) {
QFile::remove( fn );
return FALSE;
}
// okay now rename the file..
if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
f.file().latin1(), errno );
}
return TRUE;
}
/*!
Loads \a text from the document specified by \a f.
The text is required to be in UTF8 format.
Returns whether the operation succeeded.
*/
bool FileManager::loadFile( const DocLnk &f, QString &text )
{
QString fn = f.file();
QFile fl( fn );
if ( !fl.open( IO_ReadOnly ) )
return FALSE;
QTextStream ts( &fl );
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
// The below should work, but doesn't in Qt 2.3.0
ts.setCodec( QTextCodec::codecForMib( 106 ) );
#else
ts.setEncoding( QTextStream::UnicodeUTF8 );
#endif
text = ts.read();
fl.close();
return TRUE;
}
/*!
Loads \a ba from the document specified by \a f.
Returns whether the operation succeeded.
*/
bool FileManager::loadFile( const DocLnk &f, QByteArray &ba )
{
QString fn = f.file();
QFile fl( fn );
if ( !fl.open( IO_ReadOnly ) )
return FALSE;
ba.resize( fl.size() );
if ( fl.size() > 0 )
fl.readBlock( ba.data(), fl.size() );
fl.close();
return TRUE;
}
/*!
Copies the document specified by \a src to the document specified
by \a dest.
Returns whether the operation succeeded.
*/
bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
{
QFile sf( src.file() );
if ( !sf.open( IO_ReadOnly ) )
return FALSE;
QString fn = dest.file() + ".new";
ensurePathExists( fn );
QFile df( fn );
if ( !df.open( IO_WriteOnly|IO_Raw ) )
return FALSE;
const int bufsize = 16384;
char buffer[bufsize];
bool ok = TRUE;
int bytesRead = 0;
while ( ok && !sf.atEnd() ) {
bytesRead = sf.readBlock( buffer, bufsize );
if ( bytesRead < 0 )
ok = FALSE;
while ( ok && bytesRead > 0 ) {
int bytesWritten = df.writeBlock( buffer, bytesRead );
if ( bytesWritten < 0 )
ok = FALSE;
else
bytesRead -= bytesWritten;
}
}
if ( ok )
ok = dest.writeLink();
if ( ok ) {
// okay now rename the file...
if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) {
qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
dest.file().latin1(), errno );
// remove the tmp file, otherwise, it will just lay around...
QFile::remove( fn.latin1() );
}
} else {
QFile::remove( fn.latin1() );
}
return ok;
}
bool FileManager::copyFile( const QString & src, const QString & dest ) {
bool success = true;
struct stat status;
int read_fd=0;
int write_fd=0;
struct stat stat_buf;
off_t offset = 0;
QFile srcFile(src);
QFile destFile(dest);
if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
return success = false;
}
read_fd = srcFile.handle();
if(read_fd != -1) {
fstat (read_fd, &stat_buf);
if( !destFile.open( IO_WriteOnly|IO_Raw ) )
return success = false;
write_fd = destFile.handle();
if(write_fd != -1) {
int err=0;
QString msg;
#ifdef Q_OS_MACX
#ifdef SENDFILE
/* FreeBSD does support a different kind of
* sendfile. (eilers)
* I took this from Very Secure FTPd
* Licence: GPL
* Author: Chris Evans
* sysdeputil.c
*/
/* XXX - start_pos will truncate on 32-bit machines - can we
* say "start from current pos"?
*/
off_t written = 0;
int retval = 0;
retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL,
&written, 0);
/* Translate to Linux-like retval */
if (written > 0)
{
err = (int) written;
}
#else /* SENDFILE */
err == -1;
msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!";
success = false;
# warning "Need workaround for sendfile!!(eilers)"
#endif /* SENDFILE */
#else
err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
if( err == -1) {
switch(err) {
case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
case EINVAL: msg = "Descriptor is not valid or locked. ";
case ENOMEM: msg = "Insufficient memory to read from in_fd.";
case EIO: msg = "Unspecified error while reading from in_fd.";
};
success = false;
}
#endif /* Q_OS_MACX */
if( !success )
qWarning( msg );
} else {
qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
success = false;
}
} else {
qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
success = false;
}
srcFile.close();
destFile.close();
// Set file permissions
if( stat( (const char *) src, &status ) == 0 ) {
chmod( (const char *) dest, status.st_mode );
}
return success;
}
bool FileManager::renameFile( const QString & src, const QString & dest ) {
if(copyFile( src, dest )) {
if(QFile::remove(src) ) {
return true;
}
}
return false;
}
/*
bool FileManager::copyFile( const QString & src, const QString & dest ) {
bool success = true;
struct stat status;
int read_fd=0;
int write_fd=0;
struct stat stat_buf;
off_t offset = 0;
QFile srcFile(src);
QFile destFile(dest);
if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
return success = false;
}
read_fd = srcFile.handle();
if(read_fd != -1) {
fstat (read_fd, &stat_buf);
if( !destFile.open( IO_WriteOnly|IO_Raw ) )
return success = false;
write_fd = destFile.handle();
if(write_fd != -1) {
int err=0;
QString msg;
err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
if( err == -1) {
switch(err) {
case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
case EINVAL: msg = "Descriptor is not valid or locked. ";
case ENOMEM: msg = "Insufficient memory to read from in_fd.";
case EIO: msg = "Unspecified error while reading from in_fd.";
};
success = false;
}
} else {
qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
success = false;
}
} else {
qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
success = false;
}
srcFile.close();
destFile.close();
// Set file permissions
if( stat( (const char *) src, &status ) == 0 ) {
chmod( (const char *) dest, status.st_mode );
}
return success;
}
bool FileManager::renameFile( const QString & src, const QString & dest ) {
if(copyFile( src, dest )) {
if(QFile::remove(src) ) {
return true;
}
}
return false;
}
*/
/*!
Opens the document specified by \a f as a readable QIODevice.
The caller must delete the return value.
Returns 0 if the operation fails.
*/
QIODevice* FileManager::openFile( const DocLnk& f )
{
QString fn = f.file();
QFile* fl = new QFile( fn );
if ( !fl->open( IO_ReadOnly ) ) {
delete fl;
fl = 0;
}
return fl;
}
/*!
Opens the document specified by \a f as a writable QIODevice.
The caller must delete the return value.
Returns 0 if the operation fails.
*/
QIODevice* FileManager::saveFile( const DocLnk& f )
{
QString fn = f.file();
ensurePathExists( fn );
QFile* fl = new QFile( fn );
if ( fl->open( IO_WriteOnly ) ) {
f.writeLink();
} else {
delete fl;
fl = 0;
}
return fl;
}
/*!
Returns whether the document specified by \a f current exists
as a file on disk.
*/
bool FileManager::exists( const DocLnk &f )
{
return QFile::exists(f.file());
}
/*!
Ensures that the path \a fn exists, by creating required directories.
Returns TRUE if successful.
*/
bool FileManager::ensurePathExists( const QString &fn )
{
QFileInfo fi(fn);
fi.setFile( fi.dirPath(TRUE) );
if ( !fi.exists() ) {
if ( system(("mkdir -p "+fi.filePath())) )
return FALSE;
}
return TRUE;
}
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 4039243..7c29aba 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,581 +1,579 @@
/**********************************************************************
** 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"
#include <qcopchannel_qws.h>
#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();
d->newDocItem = 0;
d->showNew = newVisible;
d->catId = -2; // All files
d->toolbar = new QHBox( this );
d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars
d->toolbar->setSpacing( 0 );
d->toolbar->hide();
QWidget *spacer = new QWidget( d->toolbar );
spacer->setBackgroundMode( PaletteButton );
QToolButton *tb = new QToolButton( d->toolbar );
tb->setPixmap( Resource::loadPixmap( "close" ) );
connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );
buttonClose = tb;
tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
tb->setAutoRaise( TRUE );
QToolTip::add( tb, tr( "Close the File Selector" ) );
QPEMenuToolFocusManager::manager()->addWidget( tb );
view = new FileSelectorView( this, "fileview" );
QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );
connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
connect( view, SIGNAL( returnPressed( QListViewItem * ) ),
this, SLOT( fileClicked( QListViewItem * ) ) );
QHBox *hb = new QHBox( this );
d->typeCombo = new TypeCombo( hb );
connect( d->typeCombo, SIGNAL(selected(const QString&)),
this, SLOT(typeSelected(const QString&)) );
QWhatsThis::add( d->typeCombo, tr("Show documents of this type") );
Categories c;
c.load(categoryFileName());
QArray<int> vl( 0 );
d->catSelect = new CategorySelect( hb );
d->catSelect->setRemoveCategoryEdit( TRUE );
d->catSelect->setCategories( vl, "Document View", tr("Document View") );
d->catSelect->setAllCategories( TRUE );
connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) );
QWhatsThis::add( d->catSelect, tr("Show documents in this category") );
setCloseVisible( closeVisible );
QCopChannel *channel = new QCopChannel( "QPE/Card", this );
connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
reread();
updateWhatsThis();
}
/*!
Destroys the widget.
*/
FileSelector::~FileSelector()
{
delete d;
}
/*!
Returns the number of files in the view. If this is zero, an editor
application might bypass the selector and immediately start with
a "new" document.
*/
int FileSelector::fileCount()
{
return d->files.children().count();;
}
/*!
Calling this function is the programmatic equivalent of the user
pressing the "new" button.
\sa newSelected(), closeMe()
*/
void FileSelector::createNew()
{
DocLnk f;
emit newSelected( f );
emit closeMe();
}
void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
{
if ( !i )
return;
if ( button == Qt::LeftButton ) {
fileClicked( i );
}
}
void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int )
{
if ( !i || i == d->newDocItem )
return;
if ( button == Qt::RightButton ) {
DocLnk l = ((FileSelectorItem *)i)->file();
LnkProperties prop( &l );
prop.showMaximized();
prop.exec();
reread();
}
}
void FileSelector::fileClicked( QListViewItem *i )
{
if ( !i )
return;
if ( i == d->newDocItem ) {
createNew();
} else {
emit fileSelected( ( (FileSelectorItem*)i )->file() );
emit closeMe();
}
}
void FileSelector::typeSelected( const QString &type )
{
d->mimeFilters.clear();
QStringList subFilter = QStringList::split(";", type);
for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it )
d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
updateView();
}
void FileSelector::catSelected( int c )
{
d->catId = c;
updateView();
}
void FileSelector::cardMessage( const QCString &msg, const QByteArray &)
{
if ( msg == "mtabChanged()" )
reread();
}
/*!
Returns the selected \link doclnk.html DocLnk\endlink. The caller is
responsible for deleting the returned value.
*/
const DocLnk *FileSelector::selected()
{
FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
if ( item && item != d->newDocItem )
return new DocLnk( item->file() );
return NULL;
}
/*!
\fn void FileSelector::fileSelected( const DocLnk &f )
This signal is emitted when the user selects a document.
\a f is the document.
*/
/*!
\fn void FileSelector::newSelected( const DocLnk &f )
This signal is emitted when the user selects a "new" document.
\a f is a DocLnk for the document. You will need to set the type
of the document after copying it.
*/
/*!
\fn void FileSelector::closeMe()
This signal is emitted when the user no longer needs to view the widget.
*/
/*!
If \a b is TRUE a "new document" entry is visible; if \a b is FALSE
this entry is not visible and the user is unable to create new
documents from the dialog.
*/
void FileSelector::setNewVisible( bool b )
{
if ( d->showNew != b ) {
d->showNew = b;
updateView();
updateWhatsThis();
}
}
/*!
If \a b is TRUE a "close" or "no document" button is visible; if \a
b is FALSE this button is not visible and the user is unable to
leave the dialog without creating or selecting a document.
This function is deprecated.
*/
void FileSelector::setCloseVisible( bool b )
{
if ( b )
d->toolbar->show();
else
d->toolbar->hide();
}
/*!
*/
void FileSelector::setTypeComboVisible( bool b ) {
if ( b )
d->typeCombo->show();
else
d->typeCombo->hide();
}
/*!
*/
void FileSelector::setCategorySelectVisible( bool b ) {
if ( b )
d->catSelect->show();
else
d->catSelect->hide();
}
/*!
Rereads the list of documents.
*/
void FileSelector::reread()
{
d->files.clear();
Global::findDocuments(&d->files, filter);
d->typeCombo->reread( d->files, filter );
updateView();
}
void FileSelector::updateView()
{
FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
if ( item == d->newDocItem )
item = 0;
QString oldFile;
if ( item )
oldFile = item->file().file();
view->clear();
QListIterator<DocLnk> dit( d->files.children() );
for ( ; dit.current(); ++dit ) {
bool mimeMatch = FALSE;
if ( d->mimeFilters.count() ) {
QValueList<QRegExp>::Iterator it;
for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) {
if ( (*it).match((*dit)->type()) >= 0 ) {
mimeMatch = TRUE;
break;
}
}
} else {
mimeMatch = TRUE;
}
if ( mimeMatch &&
(d->catId == -2 || (*dit)->categories().contains(d->catId) ||
(d->catId == -1 && (*dit)->categories().isEmpty())) ) {
item = new FileSelectorItem( view, **dit );
if ( item->file().file() == oldFile )
view->setCurrentItem( item );
}
}
if ( d->showNew )
d->newDocItem = new NewDocItem( view, DocLnk() );
else
d->newDocItem = 0;
if ( !view->selectedItem() || view->childCount() == 1 ) {
view->setCurrentItem( view->firstChild() );
view->setSelected( view->firstChild(), TRUE );
}
}
void FileSelector::updateWhatsThis()
{
QWhatsThis::remove( this );
QString text = tr("Click to select a document from the list");
if ( d->showNew )
text += tr(", or select <b>New Document</b> to create a new document.");
text += tr("<br><br>Click and hold for document properties.");
QWhatsThis::add( this, text );
}
#include "fileselector.moc"
diff --git a/library/finddialog.cpp b/library/finddialog.cpp
index ddf41a7..64487c9 100644
--- a/library/finddialog.cpp
+++ b/library/finddialog.cpp
@@ -1,85 +1,84 @@
/**********************************************************************
** 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_FD
#include "finddialog.h"
#include "findwidget_p.h"
#include <qlayout.h>
-#include <qpushbutton.h>
/*!
\class FindDialog finddialog.h
\brief A simple FindDialog
A find dialog. FIXME!!!!
*/
FindDialog::FindDialog( const QString &appName, QWidget *parent,
const char *name, bool modal )
: QDialog( parent, name, modal )
{
setCaption( tr("Find") );
QVBoxLayout *vb;
vb = new QVBoxLayout( this );
fw = new FindWidget( appName, this, "Find Widget" );
vb->addWidget( fw );
QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,
bool,bool,int)),
this, SIGNAL(signalFindClicked(const QString&,
bool,bool,int)) );
QObject::connect( fw, SIGNAL(signalFindClicked(const QString&,const QDate&,
bool,bool,int)),
this, SIGNAL(signalFindClicked(const QString&,
const QDate&,bool,bool,int)) );
d = 0;
}
FindDialog::~FindDialog()
{
}
QString FindDialog::findText() const
{
return fw->findText();
}
void FindDialog::setUseDate( bool show )
{
fw->setUseDate( show );
}
void FindDialog::setDate( const QDate &dt )
{
fw->setDate( dt );
}
void FindDialog::slotNotFound()
{
fw->slotNotFound();
}
void FindDialog::slotWrapAround()
{
fw->slotWrapAround();
}
diff --git a/library/findwidget_p.cpp b/library/findwidget_p.cpp
index 287e125..e91d789 100644
--- a/library/findwidget_p.cpp
+++ b/library/findwidget_p.cpp
@@ -1,120 +1,114 @@
/**********************************************************************
** 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 "findwidget_p.h"
-#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include <qpe/datebookmonth.h>
-#include <qpe/timestring.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlineedit.h>
-#include <qmessagebox.h>
-#include <qpushbutton.h>
-#include <qpopupmenu.h>
-#include <qtoolbutton.h>
FindWidget::FindWidget( const QString &appName, QWidget *parent,
const char *name )
: FindWidgetBase( parent, name ),
mStrApp( appName ),
mDate( QDate::currentDate() )
{
setMaximumSize( sizeHint() );
QArray<int> vl(0);
cmbCat->setCategories( vl, mStrApp );
cmbCat->setRemoveCategoryEdit( TRUE );
cmbCat->setAllCategories( TRUE );
// hide junk for the moment...
lblStartDate->hide();
cmdStartDate->hide();
QPopupMenu *m1 = new QPopupMenu( this );
dtPicker = new DateBookMonth( m1, 0, TRUE );
dtPicker->setDate( mDate.year(), mDate.month(), mDate.day() );
m1->insertItem( dtPicker );
cmdStartDate->setPopup( m1 );
cmdStartDate->setText( TimeString::shortDate(mDate) );
QObject::connect( dtPicker, SIGNAL(dateClicked(int, int, int)),
this, SLOT(slotDateChanged(int, int, int)) );
QObject::connect( cmdFind, SIGNAL(clicked()),
this, SLOT(slotFindClicked()) );
}
FindWidget::~FindWidget()
{
}
QString FindWidget::findText() const
{
return txtFind->text();
}
void FindWidget::slotFindClicked()
{
lblStatus->setText( "" );
if ( cmdStartDate->isVisible() )
emit signalFindClicked( findText(),
mDate,
chkCase->isChecked(),
chkBackwards->isChecked(),
cmbCat->currentCategory() );
else
emit signalFindClicked( findText(), chkCase->isChecked(),
chkBackwards->isChecked(),
cmbCat->currentCategory() );
}
void FindWidget::setUseDate( bool show )
{
if ( show ) {
lblStartDate->show();
cmdStartDate->show();
} else {
lblStartDate->hide();
cmdStartDate->hide();
}
chkBackwards->setDisabled( show );
}
void FindWidget::setDate( const QDate &dt )
{
slotDateChanged( dt.year(), dt.month(), dt.day() );
}
void FindWidget::slotNotFound()
{
lblStatus->setText( tr("String Not Found.") );
}
void FindWidget::slotWrapAround()
{
lblStatus->setText( tr("End reached, starting at %1", "Date using TimeString::shortDate")
.arg(TimeString::shortDate( mDate ) ) );
}
void FindWidget::slotDateChanged( int year, int month, int day )
{
mDate.setYMD( year, month, day );
cmdStartDate->setText( TimeString::shortDate( mDate ) );
dtPicker->setDate( year, month, day );
}
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index 2ad8e95..d94e338 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,253 +1,251 @@
/**********************************************************************
** 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>
#include <qfontmanager_qws.h>
#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
#ifndef QWS
QStringList list;
return list;
#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
#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 QWS
return;
#else
#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";
#ifdef Q_OS_MACX
QDir dir( path, "lib*.dylib" );
#else
QDir dir( path, "lib*.so" );
#endif
if ( !dir.exists())
return;
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
#endif
}
/*!
\internal
*/
void FontDatabase::readFonts( QFontFactory *factory )
{
#ifndef QWS
return;
#else
// 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);
#endif
}
diff --git a/library/global.cpp b/library/global.cpp
index a627348..5ac969b 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,814 +1,812 @@
/**********************************************************************
** 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>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/config.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>
#include <errno.h>
#include <qwindowsystem_qws.h> // for qwsServer
#include <qdatetime.h>
-#include <qfile.h>
//#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 )
{
#if QT_VERSION >= 232 && defined(QWS)
connect( qwsServer, SIGNAL( newChannel(const QString&)),
this, SLOT( handleNewChannel(const QString&)) );
#endif
dict.setAutoDelete( TRUE );
}
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 implementation of the writeHWClock() function depends on the AlarmServer
implementation. If the AlarmServer is using atd the clock will be synced to
hardware. If opie-alarm is used the hardware clock will be synced before
suspending the device. opie-alarm is used by iPAQ and Zaurii implementation
\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(QT_NO_COP)
QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
e << message;
#endif
}
/*!
\internal
*/
void Global::applyStyle()
{
#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(QT_NO_COP)
QCopChannel::send( "QPE/System", "shutdown()" );
#endif
return 0;
}
/*!
\internal
*/
QWidget *Global::restart( bool )
{
#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(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(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(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 ) ) {
// FIXME take it out for now, since it leads to a much to short showing of wait if
// some entry is clicked.
// Real cause is that ::execute is called twice for document tab. But it would need some larger changes
// to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
// had the idea that an apploader belongs to the launcher ...
//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(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
#ifdef Q_OS_MACX
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
#else
QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
#endif
qDebug("libfile = %s", libexe.latin1() );
if ( QFile::exists( libexe ) ) {
qDebug("calling quickexec %s", libexe.latin1() );
quickexecv( libexe.utf8().data(), (const char **)args );
} else
#endif
{
bool success = false;
int pfd [2];
if ( ::pipe ( pfd ) < 0 )
pfd [0] = pfd [1] = -1;
pid_t pid = ::fork ( );
if ( pid == 0 ) { // child
for ( int fd = 3; fd < 100; fd++ ) {
if ( fd != pfd [1] )
::close ( fd );
}
::setpgid ( ::getpid ( ), ::getppid ( ));
// Closing of fd[1] indicates that the execvp succeeded!
if ( pfd [1] >= 0 )
::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
// Try bindir first, so that foo/bar works too
::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
::execvp ( args [0], (char * const *) args );
char resultByte = 1;
if ( pfd [1] >= 0 )
::write ( pfd [1], &resultByte, 1 );
::_exit ( -1 );
}
else if ( pid > 0 ) {
success = true;
if ( pfd [1] >= 0 )
::close ( pfd [1] );
if ( pfd [0] >= 0 ) {
while ( true ) {
char resultByte;
int n = ::read ( pfd [0], &resultByte, 1 );
if ( n == 1 ) {
success = false;
break;
}
if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
continue;
break; // success
}
::close ( pfd [0] );
}
}
if ( success )
StartingAppList::add( list[0] );
else
QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
}
#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 )
{
// ask the server to do the work
#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;
}
/*!
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();
Config conf((*it)->path() + "/.opiestorage.cf", Config::File );
conf.setGroup("main");
if (!conf.readBoolEntry("check",true)) {
continue;
}
conf.setGroup("subdirs");
if (conf.readBoolEntry("wholemedia",true)) {
DocLnkSet ide( path,mimefilter);
folder->appendFrom(ide);
} else {
QStringList subDirs = conf.readListEntry("subdirs",':');
if (subDirs.isEmpty()) {
subDirs.append("Documents");
}
for (unsigned c = 0; c < subDirs.count();++c) {
DocLnkSet ide( path+"/"+subDirs[c], 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()
{
QString qpeDir = QPEApplication::qpeDir();
QStringList path;
QStringList langs = Global::languageList();
for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
QString lang = *it;
if ( !lang.isEmpty() )
path += qpeDir + "/help/" + lang + "/html";
}
path += qpeDir + "/pics";
path += qpeDir + "/help/html";
/* we even put english into the en dir so try it as fallback as well for opie */
path += qpeDir + "/help/en/html";
path += qpeDir + "/docs";
return path;
}
#include "global.moc"
diff --git a/library/imageedit.cpp b/library/imageedit.cpp
index caa538a..3a559f4 100644
--- a/library/imageedit.cpp
+++ b/library/imageedit.cpp
@@ -1,97 +1,96 @@
/**********************************************************************
** 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 "imageedit.h"
-#include <qpainter.h>
ImageEdit::ImageEdit( QWidget *parent, const char *name)
: QScrollView( parent, name, WNorthWestGravity | WResizeNoErase ), buffer()
{
buffer.resize( size() );
buffer.fill( colorGroup().color( QColorGroup::Base ) );
}
ImageEdit::~ImageEdit()
{
}
void ImageEdit::contentsMousePressEvent( QMouseEvent *e )
{
lastPos = e->pos();
}
void ImageEdit::contentsMouseMoveEvent( QMouseEvent *e )
{
QPainter pw( viewport() );
QPainter pb( &buffer );
pb.drawLine( lastPos, e->pos() );
pw.drawLine( contentsToViewport( lastPos ),
contentsToViewport( e->pos() ) );
lastPos = e->pos();
}
void ImageEdit::contentsMouseReleaseEvent( QMouseEvent * )
{
}
void ImageEdit::viewportResizeEvent( QResizeEvent *e )
{
enlargeBuffer(e->size());
}
void ImageEdit::enlargeBuffer( const QSize& sz )
{
QSize osz = buffer.size();
QSize nsz( QMAX( osz.width(), sz.width() ), QMAX( osz.height(), sz.height() ) );
buffer.resize( nsz.width(), nsz.height() );
// clear new area
QPainter p( &buffer );
if ( sz.width() > osz.width() )
p.fillRect( osz.width(), 0, sz.width() - osz.width(), nsz.height(), colorGroup().color( QColorGroup::Base ) );
if ( sz.height() > osz.height() )
p.fillRect( 0, osz.height(), nsz.width(), sz.height() - osz.height(), colorGroup().color( QColorGroup::Base ) );
p.end();
}
void ImageEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
{
p->drawPixmap( cx, cy, buffer, cx, cy, cw, ch );
}
void ImageEdit::setPixmap( const QPixmap &pm )
{
QSize osz = buffer.size();
if ( pm.width() < osz.width() || pm.height() < osz.height() ) {
buffer.fill(white);
enlargeBuffer( pm.size() );
QPainter p(&buffer);
p.drawPixmap(0,0,pm);
} else {
buffer = pm;
}
resizeContents( buffer.width(), buffer.height() );
viewport()->repaint( FALSE );
}
QPixmap ImageEdit::pixmap() const
{
return buffer;
}
diff --git a/library/ir.cpp b/library/ir.cpp
index b5b726d..32c0925 100644
--- a/library/ir.cpp
+++ b/library/ir.cpp
@@ -1,118 +1,116 @@
/**********************************************************************
** 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>
#include "qcopenvelope_qws.h"
-#include <qcopchannel_qws.h>
#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 8dca4ab..0661423 100644
--- a/library/lnkproperties.cpp
+++ b/library/lnkproperties.cpp
@@ -1,347 +1,346 @@
/**********************************************************************
** 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 "lnkproperties.h"
#include "ir.h"
#include <qpe/qpeapplication.h>
#include <qpe/applnk.h>
#include <qpe/global.h>
#include <qpe/categorywidget.h>
#include <qpe/qcopenvelope_qws.h>
#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 );
// hide custom rotation feature for now, need a new implementation to fit quicklauch,
// is confusing for the user and doubtable useful since life rotation
d->rotate->hide();
d->rotateButtons->hide();
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 );
//don't use rotate buttons for now (see comment above)
//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() == "/dev/root" ||
(*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;
}
}
if ( !d->rotate->isHidden()) {
QString newrot;
if ( d->rotate->isChecked() ) {
int rot=0;
for(; rot<4; rot++) {
if (d->rotateButtons->find(rot)->isOn())
break;
}
newrot = QString::number((rot*90)%360);
}
if ( newrot != lnk->rotation() ) {
lnk-> setRotation(newrot);
changed = TRUE;
reloadMime = TRUE;
}
}
if ( d->preload->isHidden() && d->locationCombo->currentItem() != currentLocation ) {
moveLnk();
} else if ( changed ) {
lnk->writeLink();
}
if ( !d->preload->isHidden() ) {
Config cfg("Launcher");
cfg.setGroup("Preload");
QStringList apps = cfg.readListEntry("Apps",',');
QString exe = lnk->exec();
if ( apps.contains(exe) != d->preload->isChecked() ) {
if ( d->preload->isChecked() ) {
apps.append(exe);
#ifndef QT_NO_COP
QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
"enablePreload()");
#endif
} else {
apps.remove(exe);
#ifndef QT_NO_COP
QCopEnvelope e("QPE/Application/"+exe.local8Bit(),
"quitIfInvisible()");
#endif
}
cfg.writeEntry("Apps",apps,',');
}
}
if ( reloadMime )
MimeType::updateApplications ( );
}
QDialog::done( ok );
}
diff --git a/library/mimetype.cpp b/library/mimetype.cpp
index d0a578e..23de70b 100644
--- a/library/mimetype.cpp
+++ b/library/mimetype.cpp
@@ -1,370 +1,366 @@
/**********************************************************************
** 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
#include "mimetype.h"
#include "applnk.h"
#include "resource.h"
#include <qpe/qpeapplication.h>
#include "config.h"
#include <qfile.h>
-#include <qdict.h>
-#include <qregexp.h>
-#include <qstringlist.h>
#include <qtextstream.h>
-#include <qmap.h>
static void cleanupMime()
{
MimeType::clear();
}
class MimeTypeData {
public:
MimeTypeData(const QString& i) :
id(i)
{
apps.setAutoDelete(TRUE);
}
QString id;
QString extension;
QList<AppLnk> apps;
QString description()
{
if ( desc.isEmpty() )
desc = QPEApplication::tr("%1 document").arg(apps.first()->name());
return desc;
}
QPixmap regIcon()
{
if ( regicon.isNull() )
loadPixmaps();
return regicon;
}
QPixmap bigIcon()
{
if ( bigicon.isNull() )
loadPixmaps();
return bigicon;
}
private:
void loadPixmaps()
{
if ( apps.count() ) {
QString icon;
for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) {
QStringList icons = lnk->mimeTypeIcons();
if ( icons.count() ) {
QStringList types = lnk->mimeTypes();
for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) {
if ( *t == id ) {
icon = *i;
break;
}
}
}
}
if ( icon.isNull() ) {
AppLnk* lnk = apps.first();
regicon = lnk->pixmap();
bigicon = lnk->bigPixmap();
} else {
QImage unscaledIcon = Resource::loadImage( icon );
regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) );
}
}
}
QPixmap regicon;
QPixmap bigicon;
QString desc;
};
class MimeType::Private : public QDict<MimeTypeData> {
public:
Private() {}
~Private() {}
// ...
};
MimeType::Private* MimeType::d=0;
static QMap<QString,QString> *typeFor = 0;
static QMap<QString,QStringList> *extFor = 0;
MimeType::Private& MimeType::data()
{
if ( !d ) {
d = new Private;
d->setAutoDelete(TRUE);
static bool setCleanup = FALSE;
if ( !setCleanup ) {
qAddPostRoutine( cleanupMime );
setCleanup = TRUE;
}
}
return *d;
}
/*!
\class MimeType mimetype.h
\brief The MimeType class provides MIME type information.
A MimeType object is a light-weight value which
provides information about a MIME type.
\ingroup qtopiaemb
*/
/*!
Constructs a MimeType.
Normally, \a ext_or_id is a MIME type,
but if \a ext_or_id starts with / or contains no /,
it is interpretted as a filename and the
extension (eg. .txt) is used as the
MIME type.
*/
MimeType::MimeType( const QString& ext_or_id )
{
init(ext_or_id);
}
/*!
Constructs a MimeType from the type() of \a lnk.
*/
MimeType::MimeType( const DocLnk& lnk )
{
init(lnk.type());
}
/*!
Returns the MIME type identifier.
*/
QString MimeType::id() const
{
return i;
}
/*!
Returns a description of the MIME Type. This is usually based
on the application() associated with the type.
*/
QString MimeType::description() const
{
MimeTypeData* d = data(i);
return d ? d->description() : QString::null;
}
/*!
Returns a small QPixmap appropriate for the MIME type.
*/
QPixmap MimeType::pixmap() const
{
MimeTypeData* d = data(i);
return d ? d->regIcon() : QPixmap();
}
/*!
\internal
This function is not generally available.
*/
QString MimeType::extension() const
{
return extensions().first();
}
/*!
\internal
This function is not generally available.
*/
QStringList MimeType::extensions() const
{
loadExtensions();
return *(*extFor).find(i);
}
/*!
Returns a larger QPixmap appropriate for the MIME type.
*/
QPixmap MimeType::bigPixmap() const
{
MimeTypeData* d = data(i);
return d ? d->bigIcon() : QPixmap();
}
/*!
Returns the AppLnk defining the application associated
with this MIME type, or 0 if none is associated.
The caller must not retain the pointer,
but of course you can dereference it to take a copy if needed.
\sa Service::binding()
*/
const AppLnk* MimeType::application() const
{
MimeTypeData* d = data(i);
return d ? d->apps.first() : 0;
}
static QString serviceBinding(const QString& service)
{
// Copied from qtopiaservices
QString svrc = service;
for (int i=0; i<(int)svrc.length(); i++)
if ( svrc[i]=='/' ) svrc[i] = '-';
return "Service-"+svrc;
}
/*!
\internal
*/
void MimeType::registerApp( const AppLnk& lnk )
{
QStringList list = lnk.mimeTypes();
for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
MimeTypeData* cur = data()[*it];
AppLnk* l = new AppLnk(lnk);
if ( !cur ) {
cur = new MimeTypeData( *it );
data().insert( *it, cur );
cur->apps.append(l);
} else if ( cur->apps.count() ) {
Config binding(serviceBinding("Open/"+*it));
binding.setGroup("Service");
QString def = binding.readEntry("default");
if ( l->exec() == def )
cur->apps.prepend(l);
else
cur->apps.append(l);
} else {
cur->apps.append(l);
}
}
}
/*!
\internal
*/
void MimeType::clear()
{
delete d;
d = 0;
}
void MimeType::loadExtensions()
{
if ( !typeFor ) {
extFor = new QMap<QString,QStringList>;
typeFor = new QMap<QString,QString>;
loadExtensions("/etc/mime.types");
loadExtensions(QPEApplication::qpeDir()+"etc/mime.types");
}
}
void MimeType::loadExtensions(const QString& filename)
{
QFile file(filename);
if ( file.open(IO_ReadOnly) ) {
QTextStream in(&file);
QRegExp space("[ \t]+");
while (!in.atEnd()) {
QStringList tokens = QStringList::split(space, in.readLine());
QStringList::ConstIterator it = tokens.begin();
if ( it != tokens.end() ) {
QString id = *it; ++it;
// new override old (though left overrides right)
QStringList exts = (*extFor)[id];
QStringList newexts;
while ( it != tokens.end() ) {
exts.remove(*it);
if ( !newexts.contains(*it) )
newexts.append(*it);
(*typeFor)[*it] = id;
++it;
}
(*extFor)[id] = newexts + exts;
}
}
}
}
void MimeType::init( const QString& ext_or_id )
{
if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) {
i = ext_or_id.lower();
} else {
loadExtensions();
int dot = ext_or_id.findRev('.');
QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id;
i = (*typeFor)[ext.lower()];
if ( i.isNull() )
i = "application/octet-stream";
}
static bool appsUpdated = FALSE;
if ( !appsUpdated ) {
appsUpdated = TRUE;
updateApplications();
}
}
MimeTypeData* MimeType::data(const QString& id)
{
MimeTypeData* d = data()[id];
if ( !d ) {
int s = id.find('/');
QString idw = id.left(s)+"/*";
d = data()[idw];
}
return d;
}
/*!
Returns a Qtopia folder containing application definitions.
*/
QString MimeType::appsFolderName()
{
return QPEApplication::qpeDir() + "apps";
}
/*!
Reloads application definitions.
*/
void MimeType::updateApplications()
{
clear();
AppLnkSet apps( appsFolderName() );
updateApplications(&apps);
}
void MimeType::updateApplications(AppLnkSet* folder)
{
for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) {
registerApp(*it.current());
}
}
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp
index 0aac32b..8f58787 100644
--- a/library/qcopenvelope_qws.cpp
+++ b/library/qcopenvelope_qws.cpp
@@ -1,147 +1,145 @@
/**********************************************************************
** 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.
**
**********************************************************************/
#ifndef QT_NO_COP
#include "qcopenvelope_qws.h"
#endif
-#include "global.h"
#include <qbuffer.h>
-#include <qdatastream.h>
#include <qfile.h>
#include <unistd.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#ifndef QT_NO_COP
/*!
\class QCopEnvelope qcopenvelope_qws.h
\brief The QCopEnvelope class encapsulates and sends QCop messages
over QCopChannels.
QCop messages allow applications to communicate with each other.
These messages are sent using QCopEnvelope, and received by connecting
to a QCopChannel.
To send a message, use the following protocol:
\code
QCopEnvelope e(channelname, messagename);
e << parameter1 << parameter2 << ...;
\endcode
For messages without parameters, simply use:
\code
QCopEnvelope e(channelname, messagename);
\endcode
(Do not try to simplify this further as it may confuse some
compilers.)
The \c{channelname} of channels within Qtopia all start with "QPE/".
The \c{messagename} is a function identifier followed by a list of types
in parentheses. There is no whitespace in the message name.
To receive a message, you will generally just use your application's
predefined QPE/Application/\e{appname} channel
(see QPEApplication::appMessage()), but you can make another channel
and connect it to a slot like this:
\code
myChannel = new QCopChannel( "QPE/FooBar", this );
connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) );
\endcode
See also, the \link qcop.html list of Qtopia messages\endlink.
*/
/*!
Constructs a QCopEnvelope that will write \a message to \a channel.
If \a message has parameters, you must then use operator<<() to
add these parameters to the envelope.
*/
QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
QDataStream(new QBuffer),
ch(channel), msg(message)
{
device()->open(IO_WriteOnly);
}
/*!
Writes the message and then destroys the QCopEnvelope.
*/
QCopEnvelope::~QCopEnvelope()
{
QByteArray data = ((QBuffer*)device())->buffer();
const int pref=16;
if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
QString qcopfn("/tmp/qcop-msg-");
qcopfn += ch.mid(pref);
QFile qcopfile(qcopfn);
if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
#ifndef Q_OS_WIN32
if(flock(qcopfile.handle(), LOCK_EX)) {
/* some error occurred */
qWarning(QString("Failed to obtain file lock on %1 (%2)")
.arg(qcopfn).arg( errno ));
}
#endif
{
QDataStream ds(&qcopfile);
ds << ch << msg << data;
qcopfile.flush();
#ifndef Q_OS_WIN32
flock(qcopfile.handle(), LOCK_UN);
#endif
qcopfile.close();
}
QByteArray b;
QDataStream stream(b, IO_WriteOnly);
stream << QString(ch.mid(pref));
QCopChannel::send("QPE/Server", "processQCop(QString)", b);
delete device();
return;
} else {
qWarning(QString("Failed to open file %1")
.arg(qcopfn));
} // endif open
}
else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
// If this is a message that should go along the SOAP channel, we move the
// endpoint URL to the data section.
QString endpoint = ch.mid(9);
ch = "QPE/SOAP";
// Since byte arrays are explicitly shared, this is appended to the data variable..
*this << endpoint;
}
QCopChannel::send(ch,msg,data);
delete device();
}
#endif
diff --git a/library/qdawg.cpp b/library/qdawg.cpp
index af5dc82..2ea5734 100644
--- a/library/qdawg.cpp
+++ b/library/qdawg.cpp
@@ -1,627 +1,625 @@
/**********************************************************************
** 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 "qdawg.h"
#include <qintdict.h>
-#include <qvaluelist.h>
-#include <qtextstream.h>
#include <qfile.h>
#include <qtl.h>
#include <limits.h>
#include <stdio.h>
// for mmap
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
class QDawgPrivate;
class QTrie;
typedef QValueList<QTrie*> TrieClub;
typedef QIntDict<TrieClub> TrieClubDirectory;
class TriePtr {
public:
QChar letter;
QTrie* p;
int operator <(const TriePtr& o) const;
int operator >(const TriePtr& o) const;
int operator <=(const TriePtr& o) const;
};
class TrieList : public QValueList<TriePtr> {
bool sorted;
public:
TrieList()
{
sorted=TRUE;
}
QTrie* findAdd(QChar c);
bool equal(TrieList& l);
void sort()
{
if ( !sorted ) {
qHeapSort(*this);
sorted = TRUE;
}
}
};
// A fast but memory-wasting temporary class. The Dawg is the goal.
class QTrie {
public:
QTrie();
~QTrie();
void insertWord(const QString& s, uint index=0);
bool equal(QTrie* o);
void dump(int indent=0);
private:
TrieList children;
bool isword;
friend class QDawgPrivate;
int maxdepth;
int decendants;
int key;
void distributeKeys(TrieClubDirectory& directory);
QTrie* clubLeader(TrieClubDirectory& directory);
int collectKeys();
friend class TriePtr;
friend class TrieList;
};
QTrie::QTrie()
{
key = 0;
isword = FALSE;
}
QTrie::~QTrie()
{
// NOTE: we do not delete the children - after conversion to DAWG
// it's too difficult. The QTrie's are deleted via the directory.
}
void QTrie::insertWord(const QString& s, uint index)
{
if ( index == s.length() ) {
isword = TRUE;
} else {
QTrie* t = children.findAdd(s[index]);
t->insertWord(s,index+1);
}
}
bool QTrie::equal(QTrie* o)
{
if ( o == this ) return TRUE;
if ( isword != o->isword )
return FALSE;
return children.equal(o->children);
}
void QTrie::dump(int indent)
{
for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
QTrie* s = (*it).p;
for (int in=0; in<indent; in++)
fputc(' ',stderr);
fprintf(stderr," %c %d %s %p\n",(*it).letter.unicode(),
s->key,s->isword?"word":"",s);
s->dump(indent+2);
}
}
void QTrie::distributeKeys(TrieClubDirectory& directory)
{
maxdepth = INT_MIN;
decendants = children.count();
key = 0;
for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
QTrie* s = (*it).p;
QChar l = (*it).letter;
s->distributeKeys(directory);
key = key*64+l.unicode()+s->key*5;
decendants += s->decendants;
if ( s->maxdepth+1 > maxdepth )
maxdepth = s->maxdepth+1;
}
if ( decendants ) {
key += decendants + maxdepth*256 + children.count() * 65536;
if ( !key ) key++; // unlikely
}
TrieClub* c = directory[key];
if ( !c ) directory.insert(key, (c = new TrieClub) );
c->prepend(this);
}
QTrie* QTrie::clubLeader(TrieClubDirectory& directory)
{
if ( !key ) return directory[0]->first();
for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it) {
QTrie* t= (*it).p->clubLeader(directory);
(*it).p = t;
}
TrieClub *club = directory[key];
for (TrieClub::Iterator it = club->begin(); it != club->end(); ++it) {
QTrie* o = *it;
if ( o->equal(this) )
return o;
}
return this;
}
int QTrie::collectKeys()
{
int n=0;
if ( key ) key=0,n+=children.count();
for (TrieList::Iterator it=children.begin(); it!=children.end(); ++it)
n += (*it).p->collectKeys();
return n;
}
int TriePtr::operator <(const TriePtr& o) const
{ return letter < o.letter; }
int TriePtr::operator >(const TriePtr& o) const
{ return letter > o.letter; }
int TriePtr::operator <=(const TriePtr& o) const
{ return letter <= o.letter; }
bool TrieList::equal(TrieList& l)
{
if ( count() != l.count() )
return FALSE;
sort(); l.sort();
ConstIterator it2 = begin();
ConstIterator it = l.begin();
for( ; it != l.end(); ++it, ++it2 )
if ( (*it).letter != (*it2).letter || ! (*it).p->equal((*it2).p) )
return FALSE;
return TRUE;
}
QTrie* TrieList::findAdd(QChar c)
{
for (Iterator it=begin(); it!=end(); ++it) {
if ( (*it).letter == c )
return (*it).p;
}
TriePtr p;
p.p = new QTrie;
p.letter = c;
prepend(p);
sorted=FALSE;
sort();
return p.p;
}
static const char* dawg_sig = "QDAWG100";
class QDawgPrivate {
public:
QDawgPrivate(QIODevice* dev)
{
QDataStream ds(dev);
char sig[8];
ds.readRawBytes(sig,8);
if ( !strncmp(dawg_sig,sig,8) ) {
uint n;
char* nn;
ds.readBytes(nn,n);
// #### endianness problem ignored.
node = (QDawg::Node*)nn;
nodes = n / sizeof(QDawg::Node);
} else {
node = 0;
}
}
bool ok() const { return node; }
QDawgPrivate(uchar* mem)
{
if ( !strncmp(dawg_sig,(char*)mem,8) ) {
mem += 8;
int n = ((mem[0]*256+mem[1])*256+mem[2])*256+mem[3];
mem += 4;
// #### endianness problem ignored.
node = (QDawg::Node*)((char*)mem);
nodes = n / sizeof(QDawg::Node);
}
}
QDawgPrivate(QTrie* t) // destroys the QTrie.
{
TrieClubDirectory directory(9973);
t->distributeKeys(directory);
QTrie* l = t->clubLeader(directory);
ASSERT(l==t);
generateArray(t);
TrieClub *club;
for (QIntDictIterator<TrieClub> dit(directory); (club=dit); ++dit)
{
for (TrieClub::Iterator it = club->begin(); it != club->end(); ++it) {
delete *it;
}
delete club;
}
}
bool write(QIODevice* dev)
{
QDataStream ds(dev);
ds.writeRawBytes(dawg_sig,8);
// #### endianness problem ignored.
ds.writeBytes((char*)node,sizeof(QDawg::Node)*nodes);
return dev->state() == IO_Ok;
}
void dumpWords(int nid=0, int index=0)
{
static char word[256]; // ick latin1
int i=0;
do {
QDawg::Node& n = node[nid+i];
word[index] = n.let;
if ( n.isword )
fprintf(stderr,"%.*s\n",index+1,word);
if ( n.offset ) dumpWords(n.offset+nid+i,index+1);
} while (!node[nid+i++].islast);
}
void dump(int nid=0, int indent=0)
{
int i=0;
do {
QDawg::Node& n = node[nid+i];
fprintf(stderr,"%d: ",nid+i);
for (int in=0; in<indent; in++)
fputc(' ',stderr);
fprintf(stderr," %c %d %d %d\n",n.let,
n.isword,n.islast,n.offset);
if ( n.offset ) dump(n.offset+nid+i,indent+2);
} while (!node[nid+i++].islast);
}
int countWords(int nid=0)
{
int t=0;
int i=0;
do {
QDawg::Node& n = node[nid+i];
if ( n.isword )
t++;
if ( n.offset )
t+=countWords(n.offset+nid+i);
} while (!node[nid+i++].islast);
return t;
}
bool contains(const QString& s, int nid=0, int index=0) const
{
int i=0;
do {
QDawg::Node& n = node[nid+i];
if ( s[index] == QChar((ushort)n.let) ) {
if ( n.isword && index == (int)s.length()-1 )
return TRUE;
if ( n.offset )
return contains(s,n.offset+nid+i,index+1);
}
} while (!node[nid+i++].islast);
return FALSE;
}
void appendAllWords(QStringList& list, int nid=0, QString s="") const
{
int i=0;
int next = s.length();
do {
QDawg::Node& n = node[nid+i];
s[next] = QChar((ushort)n.let);
if ( n.isword )
list.append(s);
if ( n.offset )
appendAllWords(list, n.offset+nid+i, s);
} while (!node[nid+i++].islast);
}
const QDawg::Node* root() { return node; }
private:
void generateArray(QTrie* t)
{
nodes = 0;
int n = t->collectKeys();
node = new QDawg::Node[n];
appendToArray(t);
ASSERT(n == nodes);
}
int appendToArray(QTrie* t)
{
if ( !t->key ) {
if ( !t->children.count() )
return 0;
t->key = nodes;
nodes += t->children.count();
QDawg::Node* n = &node[t->key-1];
int here = t->key;
for (TrieList::Iterator it=t->children.begin(); it!=t->children.end(); ++it) {
QTrie* s = (*it).p;
++n;
n->let = (*it).letter.unicode();
n->isword = s->isword;
n->islast = 0;
n->offset = appendToArray(s);
if ( n->offset ) {
int t = n->offset-here;
n->offset=t;
if ( n->offset != t )
qWarning("Overflow: too many words");
}
here++;
}
n->islast = 1;
}
return t->key;
}
private:
int nodes;
QDawg::Node *node;
};
/*!
\class QDawg qdawg.h
\brief The QDawg class provides an implementation of a Directed Acyclic Word Graph.
A DAWG provides very fast look-up of words in a word list.
The word list is created using readFile(), read() or
createFromWords(). A list of all the DAWG's words is returned by
allWords(), and the total number of words is returned by
countWords(). Use contains() to see if a particular word is in the
DAWG. The root \link qdawg-node.html node\endlink is returned by root().
A global DAWG is maintained for the current locale. See the
\l Global class for details.
The structure of a DAWG is a graph of \link qdawg-node.html
Nodes\endlink. There are no cycles in the graph (since there are no
inifinitely repeating words). Each \link qdawg-node.html
Node\endlink is a member of a list of \link qdawg-node.html
Nodes\endlink called a child list. Each \link qdawg-node.html
Node\endlink in the child list has a \e letter, an \e isWord flag,
at most one \e jump arc, and at most one arc to the next child in
the list.
If you traverse the \link qdawg-node.html Nodes\endlink in a DAWG,
starting from the root(), and you concatenate all the letters from
the single child in each child list that you visit, at every \link
qdawg-node.html Node\endlink which has the isWord flag set your
concatenation will be a word in the list represented by the DAWG.
For example, the DAWG below represents the word list:
ban, band, can, cane, cans, pan, pane, pans.
This structuring not only provides O(1) lookup of words in the word list,
but also produces a smaller storage file than a plain text file word list.
\img qdawg.png
*/
/*!
Constructs a new empty DAWG.
*/
QDawg::QDawg()
{
d = 0;
}
/*!
Deletes the DAWG.
*/
QDawg::~QDawg()
{
delete d;
}
/*!
\overload
Replaces all the DAWG's words with words read from \a dev.
*/
bool QDawg::createFromWords(QIODevice* dev)
{
delete d;
QTextStream i(dev);
QTrie* trie = new QTrie;
int n=0;
while (!i.atEnd()) {
trie->insertWord(QString::fromUtf8(i.readLine()));
n++;
}
if ( n )
d = new QDawgPrivate(trie);
else
d = 0;
return TRUE;
}
/*!
Replaces all the DAWG's words with the words in the \a list.
*/
void QDawg::createFromWords(const QStringList& list)
{
delete d;
if ( list.count() ) {
QTrie* trie = new QTrie;
for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
trie->insertWord(*it);
}
d = new QDawgPrivate(trie);
} else {
d = 0;
}
}
/*!
Returns a list of all the words in the DAWG.
*/
QStringList QDawg::allWords() const
{
QStringList result;
if ( d ) d->appendAllWords(result);
return result;
}
/*!
Replaces the DAWG with the DAWG in \a filename.
The file is memory-mapped.
\sa write()
*/
bool QDawg::readFile(const QString& filename)
{
delete d;
d = 0;
int f = ::open( QFile::encodeName(filename), O_RDONLY );
if ( f < 0 )
return FALSE;
struct stat st;
if ( !fstat( f, &st ) ) {
char * tmp = (char*)mmap( 0, st.st_size, // any address, whole file
PROT_READ, // read-only memory
MAP_FILE | MAP_PRIVATE, // swap-backed map from file
f, 0 ); // from offset 0 of f
if ( tmp && tmp != (char*)MAP_FAILED )
d = new QDawgPrivate((uchar*)tmp);
}
::close( f );
return d;
}
/*!
Replaces the DAWG with the DAWG in \a dev.
The file is memory-mapped.
\sa write()
*/
bool QDawg::read(QIODevice* dev)
{
delete d;
d = new QDawgPrivate(dev);
if ( d->ok() )
return TRUE;
delete d;
d = 0;
return FALSE;
}
/*!
Writes the DAWG to \a dev, in a custom QDAWG format.
*/
bool QDawg::write(QIODevice* dev) const
{
return d ? d->write(dev) : TRUE;
}
/*!
Returns the number of words in the DAWG.
*/
int QDawg::countWords() const
{
return d ? d->countWords() : 0;
}
/*!
Returns the root \link qdawg-node.html Node\endlink of the DAWG.
*/
const QDawg::Node* QDawg::root() const
{
return d ? d->root() : 0;
}
/*!
Returns TRUE if the DAWG contains the word \a s; otherwise returns
FALSE.
*/
bool QDawg::contains(const QString& s) const
{
return d ? d->contains(s) : FALSE;
}
/*!
\internal
For debugging: prints out the DAWG contents.
*/
void QDawg::dump() const
{
if ( d ) d->dump();
}
/*!
\class QDawg::Node qdawg.h
\brief The QDawg::Node class represents one node of a QDawg.
*/
/*!
\fn QChar QDawg::Node::letter() const
Returns this Node's letter.
*/
/*!
\fn bool QDawg::Node::isWord() const
Returns TRUE if this Node is the end of a word; otherwise returns
FALSE.
*/
/*!
\fn bool QDawg::Node::isLast() const
Returns TRUE if this Node is the last in the child list; otherwise
returns FALSE.
*/
/*!
\fn const Node* QDawg::Node::next() const
Returns the next child Node in the child list or 0 if the current
Node isLast().
*/
/*!
\fn const Node* QDawg::Node::jump() const
Returns the node connected to this Node.
*/
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c7ef2b7..262221e 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2100 +1,2099 @@
/**********************************************************************
** 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 <stdlib.h>
#include <unistd.h>
#ifndef Q_OS_MACX
#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
#endif
#include <qfile.h>
#include <qqueue.h>
#ifdef Q_WS_QWS
#ifndef QT_NO_COP
#if QT_VERSION <= 231
#define private public
#define sendLocally processEvent
#include "qcopenvelope_qws.h"
#undef private
#else
#include "qcopenvelope_qws.h"
#endif
#endif
#include <qwindowsystem_qws.h>
#endif
#include <qtextstream.h>
#include <qpalette.h>
#include <qbuffer.h>
#include <qptrdict.h>
#include <qregexp.h>
#include <qdir.h>
#include <qlabel.h>
#include <qdialog.h>
#include <qdragobject.h>
#include <qtextcodec.h>
#include <qevent.h>
#include <qtooltip.h>
#include <qsignal.h>
#include <qmainwindow.h>
#include <qwidgetlist.h>
#include <qpixmapcache.h>
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
#define QTOPIA_INTERNAL_INITAPP
#include "qpeapplication.h"
#include "qpestyle.h"
#include "styleinterface.h"
#if QT_VERSION >= 300
#include <qstylefactory.h>
#else
#include <qplatinumstyle.h>
#include <qwindowsstyle.h>
#include <qmotifstyle.h>
#include <qmotifplusstyle.h>
#include "lightstyle.h"
#include <qpe/qlibrary.h>
#endif
#include "global.h"
#include "resource.h"
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
#include "qutfcodec.h"
#endif
#include "config.h"
#include "network.h"
#ifdef QWS
#include "fontmanager.h"
#endif
#include "alarmserver.h"
#include "applnk.h"
#include "qpemenubar.h"
#include "textcodecinterface.h"
#include "imagecodecinterface.h"
#include <unistd.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#ifndef QT_NO_SOUND
#include <sys/soundcard.h>
#endif
#include "qt_override_p.h"
class QPEApplicationData
{
public:
QPEApplicationData ( )
: presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
{}
int presstimer;
QWidget* presswidget;
QPoint presspos;
bool rightpressed : 1;
bool kbgrabbed : 1;
bool notbusysent : 1;
bool preloaded : 1;
bool forceshow : 1;
bool nomaximize : 1;
bool keep_running : 1;
bool qcopQok : 1;
QStringList langs;
QString appName;
struct QCopRec
{
QCopRec( const QCString &ch, const QCString &msg,
const QByteArray &d ) :
channel( ch ), message( msg ), data( d )
{ }
QCString channel;
QCString message;
QByteArray data;
};
QWidget* qpe_main_widget;
QGuardedPtr<QWidget> lastraised;
QQueue<QCopRec> qcopq;
QString styleName;
QString decorationName;
void enqueueQCop( const QCString &ch, const QCString &msg,
const QByteArray &data )
{
qcopq.enqueue( new QCopRec( ch, msg, data ) );
}
void sendQCopQ()
{
if (!qcopQok )
return;
QCopRec * r;
while((r=qcopq.dequeue())) {
// remove from queue before sending...
// event loop can come around again before getting
// back from sendLocally
#ifndef QT_NO_COP
QCopChannel::sendLocally( r->channel, r->message, r->data );
#endif
delete r;
}
}
static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null )
{
// ugly hack, remove that later after finding a sane solution
// Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
// so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
// a (physically) large enough display to use the small icons
#if defined(OPIE_HIGH_RES_SMALL_PHY)
if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
}
#endif
if ( mw->layout() && mw->inherits("QDialog") ) {
QPEApplication::showDialog((QDialog*)mw, nomaximize);
}
else {
#ifdef Q_WS_QWS
if ( !nomaximize )
mw->showMaximized();
else
#endif
mw->show();
}
}
static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
{
/*
// This works but disable it for now until it is safe to apply
// What is does is scan the .desktop files of all the apps for
// the applnk that has the corresponding argv[0] as this program
// then it uses the name stored in the .desktop file as the caption
// for the main widget. This saves duplicating translations for
// the app name in the program and in the .desktop files.
AppLnkSet apps( appsPath );
QList<AppLnk> appsList = apps.children();
for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
if ( (*it)->exec() == appName ) {
mw->setCaption( (*it)->name() );
return TRUE;
}
}
*/
return FALSE;
}
void show(QWidget* mw, bool nomax)
{
setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
nomaximize = nomax;
qpe_main_widget = mw;
qcopQok = TRUE;
#ifndef QT_NO_COP
sendQCopQ();
#endif
if ( preloaded ) {
if (forceshow)
show_mx(mw, nomax);
}
else if ( keep_running ) {
show_mx(mw, nomax);
}
}
void loadTextCodecs()
{
QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
#ifdef Q_OS_MACX
QDir dir( path, "lib*.dylib" );
#else
QDir dir( path, "lib*.so" );
#endif
QStringList list;
if ( dir. exists ( ))
list = dir.entryList();
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
TextCodecInterface *iface = 0;
QLibrary *lib = new QLibrary( path + "/" + *it );
if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
QValueList<int> mibs = iface->mibEnums();
for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
(void)iface->createForMib(*i);
// ### it exists now; need to remember if we can delete it
}
}
else {
lib->unload();
delete lib;
}
}
}
void loadImageCodecs()
{
QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
#ifdef Q_OS_MACX
QDir dir( path, "lib*.dylib" );
#else
QDir dir( path, "lib*.so" );
#endif
QStringList list;
if ( dir. exists ( ))
list = dir.entryList();
QStringList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
ImageCodecInterface *iface = 0;
QLibrary *lib = new QLibrary( path + "/" + *it );
if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
QStringList formats = iface->keys();
for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
(void)iface->installIOHandler(*i);
// ### it exists now; need to remember if we can delete it
}
}
else {
lib->unload();
delete lib;
}
}
}
};
class ResourceMimeFactory : public QMimeSourceFactory
{
public:
ResourceMimeFactory() : resImage( 0 )
{
setFilePath( Global::helpPath() );
setExtensionType( "html", "text/html;charset=UTF-8" );
}
~ResourceMimeFactory() {
delete resImage;
}
const QMimeSource* data( const QString& abs_name ) const
{
const QMimeSource * r = QMimeSourceFactory::data( abs_name );
if ( !r ) {
int sl = abs_name.length();
do {
sl = abs_name.findRev( '/', sl - 1 );
QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
int dot = name.findRev( '.' );
if ( dot >= 0 )
name = name.left( dot );
QImage img = Resource::loadImage( name );
if ( !img.isNull() ) {
delete resImage;
resImage = new QImageDrag( img );
r = resImage;
}
}
while ( !r && sl > 0 );
}
return r;
}
private:
mutable QImageDrag *resImage;
};
static int& hack(int& i)
{
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
// These should be created, but aren't in Qt 2.3.0
(void)new QUtf8Codec;
(void)new QUtf16Codec;
#endif
return i;
}
static int muted = 0;
static int micMuted = 0;
static void setVolume( int t = 0, int percent = -1 )
{
switch ( t ) {
case 0: {
Config cfg( "qpe" );
cfg.setGroup( "Volume" );
if ( percent < 0 )
percent = cfg.readNumEntry( "VolumePercent", 50 );
#ifndef QT_NO_SOUND
int fd = 0;
if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
int vol = muted ? 0 : percent;
// set both channels to same volume
vol |= vol << 8;
ioctl( fd, MIXER_WRITE( 0 ), &vol );
::close( fd );
}
#endif
}
break;
}
}
static void setMic( int t = 0, int percent = -1 )
{
switch ( t ) {
case 0: {
Config cfg( "qpe" );
cfg.setGroup( "Volume" );
if ( percent < 0 )
percent = cfg.readNumEntry( "Mic", 50 );
#ifndef QT_NO_SOUND
int fd = 0;
int mic = micMuted ? 0 : percent;
if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
::close( fd );
}
#endif
}
break;
}
}
static void setBass( int t = 0, int percent = -1 )
{
switch ( t ) {
case 0: {
Config cfg( "qpe" );
cfg.setGroup( "Volume" );
if ( percent < 0 )
percent = cfg.readNumEntry( "BassPercent", 50 );
#ifndef QT_NO_SOUND
int fd = 0;
int bass = percent;
if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
::close( fd );
}
#endif
}
break;
}
}
static void setTreble( int t = 0, int percent = -1 )
{
switch ( t ) {
case 0: {
Config cfg( "qpe" );
cfg.setGroup( "Volume" );
if ( percent < 0 )
percent = cfg.readNumEntry( "TreblePercent", 50 );
#ifndef QT_NO_SOUND
int fd = 0;
int treble = percent;
if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
::close( fd );
}
#endif
}
break;
}
}
/**
\class QPEApplication
\brief The QPEApplication class implements various system services
that are available to all Qtopia applications.
Simply by using QPEApplication instead of QApplication, a standard Qt
application becomes a Qtopia application. It automatically follows
style changes, quits and raises, and in the
case of \link docwidget.html document-oriented\endlink applications,
changes the currently displayed document in response to the environment.
To create a \link docwidget.html document-oriented\endlink
application use showMainDocumentWidget(); to create a
non-document-oriented application use showMainWidget(). The
keepRunning() function indicates whether the application will
continue running after it's processed the last \link qcop.html
QCop\endlink message. This can be changed using setKeepRunning().
A variety of signals are emitted when certain events occur, for
example, timeChanged(), clockChanged(), weekChanged(),
dateFormatChanged() and volumeChanged(). If the application receives
a \link qcop.html QCop\endlink message on the application's
QPE/Application/\e{appname} channel, the appMessage() signal is
emitted. There are also flush() and reload() signals, which
are emitted when synching begins and ends respectively - upon these
signals, the application should save and reload any data
files that are involved in synching. Most of these signals will initially
be received and unfiltered through the appMessage() signal.
This class also provides a set of useful static functions. The
qpeDir() and documentDir() functions return the respective paths.
The grabKeyboard() and ungrabKeyboard() functions are used to
control whether the application takes control of the device's
physical buttons (e.g. application launch keys). The stylus' mode of
operation is set with setStylusOperation() and retrieved with
stylusOperation(). There are also setInputMethodHint() and
inputMethodHint() functions.
\ingroup qtopiaemb
*/
/*!
\fn void QPEApplication::clientMoused()
\internal
*/
/*!
\fn void QPEApplication::timeChanged();
This signal is emitted when the time changes outside the normal
passage of time, i.e. if the time is set backwards or forwards.
*/
/*!
\fn void QPEApplication::clockChanged( bool ampm );
This signal is emitted when the user changes the clock's style. If
\a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
they want a 24-hour clock.
*/
/*!
\fn void QPEApplication::volumeChanged( bool muted )
This signal is emitted whenever the mute state is changed. If \a
muted is TRUE, then sound output has been muted.
*/
/*!
\fn void QPEApplication::weekChanged( bool startOnMonday )
This signal is emitted if the week start day is changed. If \a
startOnMonday is TRUE then the first day of the week is Monday; if
\a startOnMonday is FALSE then the first day of the week is
Sunday.
*/
/*!
\fn void QPEApplication::dateFormatChanged(DateFormat)
This signal is emitted whenever the date format is changed.
*/
/*!
\fn void QPEApplication::flush()
###
*/
/*!
\fn void QPEApplication::reload()
*/
void QPEApplication::processQCopFile()
{
QString qcopfn("/tmp/qcop-msg-");
qcopfn += d->appName; // append command name
QFile f(qcopfn);
if ( f.open(IO_ReadWrite) ) {
#ifndef Q_OS_WIN32
flock(f.handle(), LOCK_EX);
#endif
QDataStream ds(&f);
QCString channel, message;
QByteArray data;
while(!ds.atEnd()) {
ds >> channel >> message >> data;
d->enqueueQCop(channel,message,data);
}
::ftruncate(f.handle(), 0);
#ifndef Q_OS_WIN32
f.flush();
flock(f.handle(), LOCK_UN);
#endif
}
#endif
}
/*!
\fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
This signal is emitted when a message is received on this
application's QPE/Application/<i>appname</i> \link qcop.html
QCop\endlink channel.
The slot to which you connect this signal uses \a msg and \a data
in the following way:
\code
void MyWidget::receive( const QCString& msg, const QByteArray& data )
{
QDataStream stream( data, IO_ReadOnly );
if ( msg == "someMessage(int,int,int)" ) {
int a,b,c;
stream >> a >> b >> c;
...
} else if ( msg == "otherMessage(QString)" ) {
...
}
}
\endcode
\sa qcop.html
Note that messages received here may be processed by qpe application
and emitted as signals, such as flush() and reload().
*/
/*!
Constructs a QPEApplication just as you would construct
a QApplication, passing \a argc, \a argv, and \a t.
For applications, \a t should be the default, GuiClient. Only
the Qtopia server passes GuiServer.
*/
QPEApplication::QPEApplication( int & argc, char **argv, Type t )
: QApplication( hack(argc), argv, t ), pidChannel( 0 )
{
QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
d = new QPEApplicationData;
d->loadTextCodecs();
d->loadImageCodecs();
int dw = desktop() ->width();
if ( dw < 200 ) {
setFont( QFont( "vera", 8 ) );
AppLnk::setSmallIconSize( 10 );
AppLnk::setBigIconSize( 28 );
}
#if defined(OPIE_HIGH_RES_SMALL_PHY)
else if ( dw > 600 ) {
setFont( QFont( "vera", 16 ) );
AppLnk::setSmallIconSize( 24 );
AppLnk::setBigIconSize( 48 );
}
#endif
else if ( dw > 200 ) {
setFont( QFont( "vera", 10 ) );
AppLnk::setSmallIconSize( 14 );
AppLnk::setBigIconSize( 32 );
}
QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
sysChannel = new QCopChannel( "QPE/System", this );
connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
/* COde now in initapp */
#if 0
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
QString qcopfn( "/tmp/qcop-msg-" );
qcopfn += QString( argv[ 0 ] ); // append command name
QFile f( qcopfn );
if ( f.open( IO_ReadOnly ) ) {
flock( f.handle(), LOCK_EX );
}
QCString channel = QCString( argv[ 0 ] );
channel.replace( QRegExp( ".*/" ), "" );
d->appName = channel;
channel = "QPE/Application/" + channel;
pidChannel = new QCopChannel( channel, this );
connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
if ( f.isOpen() ) {
d->keep_running = FALSE;
QDataStream ds( &f );
QCString channel, message;
QByteArray data;
while ( !ds.atEnd() ) {
ds >> channel >> message >> data;
d->enqueueQCop( channel, message, data );
}
flock( f.handle(), LOCK_UN );
f.close();
f.remove();
}
for ( int a = 0; a < argc; a++ ) {
if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
argv[ a ] = argv[ a + 1 ];
a++;
d->preloaded = TRUE;
argc -= 1;
}
else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
argv[ a ] = argv[ a + 1 ];
a++;
d->preloaded = TRUE;
d->forceshow = TRUE;
argc -= 1;
}
}
/* overide stored arguments */
setArgs( argc, argv );
#endif
#else
initApp( argc, argv );
#endif
// qwsSetDecoration( new QPEDecoration() );
#ifndef QT_NO_TRANSLATION
d->langs = Global::languageList();
for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
QString lang = *it;
installTranslation( lang + "/libopie.qm");
installTranslation( lang + "/libqpe.qm" );
installTranslation( lang + "/" + d->appName + ".qm" );
//###language/font hack; should look it up somewhere
#ifdef QWS
if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
QFont fn = FontManager::unicodeFont( FontManager::Proportional );
setFont( fn );
}
#endif
}
#endif
applyStyle();
if ( type() == GuiServer ) {
setVolume();
}
installEventFilter( this );
QPEMenuToolFocusManager::initialize();
#ifdef QT_NO_QWS_CURSOR
// if we have no cursor, probably don't want tooltips
QToolTip::setEnabled( FALSE );
#endif
}
#ifdef QTOPIA_INTERNAL_INITAPP
void QPEApplication::initApp( int argc, char **argv )
{
delete pidChannel;
d->keep_running = TRUE;
d->preloaded = FALSE;
d->forceshow = FALSE;
QCString channel = QCString(argv[0]);
channel.replace(QRegExp(".*/"),"");
d->appName = channel;
#if QT_VERSION > 235
qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
#endif
channel = "QPE/Application/" + channel;
pidChannel = new QCopChannel( channel, this);
connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(pidMessage(const QCString &, const QByteArray &)));
processQCopFile();
d->keep_running = d->qcopq.isEmpty();
for (int a=0; a<argc; a++) {
if ( qstrcmp(argv[a],"-preload")==0 ) {
argv[a] = argv[a+1];
a++;
d->preloaded = TRUE;
argc-=1;
} else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
argv[a] = argv[a+1];
a++;
d->preloaded = TRUE;
d->forceshow = TRUE;
argc-=1;
}
}
/* overide stored arguments */
setArgs(argc, argv);
/* install translation here */
for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
installTranslation( (*it) + "/" + d->appName + ".qm" );
}
#endif
static QPtrDict<void>* inputMethodDict = 0;
static void createInputMethodDict()
{
if ( !inputMethodDict )
inputMethodDict = new QPtrDict<void>;
}
/*!
Returns the currently set hint to the system as to whether
widget \a w has any use for text input methods.
\sa setInputMethodHint() InputMethodHint
*/
QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
{
if ( inputMethodDict && w )
return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
return Normal;
}
/*!
\enum QPEApplication::InputMethodHint
\value Normal the application sometimes needs text input (the default).
\value AlwaysOff the application never needs text input.
\value AlwaysOn the application always needs text input.
*/
/*!
Hints to the system that widget \a w has use for text input methods
as specified by \a mode.
\sa inputMethodHint() InputMethodHint
*/
void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
{
createInputMethodDict();
if ( mode == Normal ) {
inputMethodDict->remove
( w );
}
else {
inputMethodDict->insert( w, ( void* ) mode );
}
}
class HackDialog : public QDialog
{
public:
void acceptIt()
{
accept();
}
void rejectIt()
{
reject();
}
};
void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
{
// specialised actions for certain widgets. May want to
// add more stuff here.
if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
&& activePopupWidget() ->parentWidget()
&& activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
key = Qt::Key_Return;
if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
key = Qt::Key_Return;
#ifdef QWS
ke->simpleData.keycode = key;
#endif
}
class HackWidget : public QWidget
{
public:
bool needsOk()
{
return ( getWState() & WState_Reserved1 );
}
};
/*!
\internal
*/
#ifdef QWS
bool QPEApplication::qwsEventFilter( QWSEvent * e )
{
if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
if ( qApp->type() != QApplication::GuiServer ) {
QCopEnvelope e( "QPE/System", "notBusy(QString)" );
e << d->appName;
}
d->notbusysent = TRUE;
}
if ( type() == GuiServer ) {
switch ( e->type ) {
case QWSEvent::Mouse:
if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
emit clientMoused();
break;
default:
break;
}
}
if ( e->type == QWSEvent::Key ) {
QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
if ( ke->simpleData.keycode == Qt::Key_F33 ) {
// Use special "OK" key to press "OK" on top level widgets
QWidget * active = activeWindow();
QWidget *popup = 0;
if ( active && active->isPopup() ) {
popup = active;
active = active->parentWidget();
}
if ( active && ( int ) active->winId() == ke->simpleData.window &&
!active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
if ( ke->simpleData.is_press ) {
if ( popup )
popup->close();
if ( active->inherits( "QDialog" ) ) {
HackDialog * d = ( HackDialog * ) active;
d->acceptIt();
return TRUE;
}
else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
QSignal s;
s.connect( active, SLOT( accept() ) );
s.activate();
}
else {
// do the same as with the select key: Map to the default action of the widget:
mapToDefaultAction( ke, Qt::Key_Return );
}
}
}
}
else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
// Use special "select" key to do whatever default action a widget has
mapToDefaultAction( ke, Qt::Key_Space );
}
else if ( ke->simpleData.keycode == Qt::Key_Escape &&
ke->simpleData.is_press ) {
// Escape key closes app if focus on toplevel
QWidget * active = activeWindow();
if ( active && active->testWFlags( WType_TopLevel ) &&
( int ) active->winId() == ke->simpleData.window &&
!active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
if ( active->inherits( "QDialog" ) ) {
HackDialog * d = ( HackDialog * ) active;
d->rejectIt();
return TRUE;
}
else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
active->close();
}
}
}
else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
// this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
// but we cannot access libopie function within libqpe :(
QWidget * active = activeWindow ( );
if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
if ( d-> kbgrabbed ) { // we grabbed the keyboard
QChar ch ( ke-> simpleData.unicode );
QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
ke-> simpleData.keycode,
ch. latin1 ( ),
ke-> simpleData.modifiers,
QString ( ch ),
ke-> simpleData.is_auto_repeat, 1 );
QObject *which = QWidget::keyboardGrabber ( );
if ( !which )
which = QApplication::focusWidget ( );
if ( !which )
which = QApplication::activeWindow ( );
if ( !which )
which = qApp;
QApplication::sendEvent ( which, &qke );
}
else { // we didn't grab the keyboard, so send the event to the launcher
QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
}
}
return true;
}
}
if ( e->type == QWSEvent::Focus ) {
QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
if ( !fe->simpleData.get_focus ) {
QWidget * active = activeWindow();
while ( active && active->isPopup() ) {
active->close();
active = activeWindow();
}
}
else {
// make sure our modal widget is ALWAYS on top
QWidget *topm = activeModalWidget();
if ( topm ) {
topm->raise();
}
}
if ( fe->simpleData.get_focus && inputMethodDict ) {
InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
if ( m == AlwaysOff )
Global::hideInputMethod();
if ( m == AlwaysOn )
Global::showInputMethod();
}
}
return QApplication::qwsEventFilter( e );
}
#endif
/*!
Destroys the QPEApplication.
*/
QPEApplication::~QPEApplication()
{
ungrabKeyboard();
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
// Need to delete QCopChannels early, since the display will
// be gone by the time we get to ~QObject().
delete sysChannel;
delete pidChannel;
#endif
delete d;
}
/*!
Returns <tt>$OPIEDIR/</tt>.
*/
QString QPEApplication::qpeDir()
{
const char * base = getenv( "OPIEDIR" );
if ( base )
return QString( base ) + "/";
return QString( "../" );
}
/*!
Returns the user's current Document directory. There is a trailing "/".
.. well, it does now,, and there's no trailing '/'
*/
QString QPEApplication::documentDir()
{
const char* base = getenv( "HOME");
if ( base )
return QString( base ) + "/Documents";
return QString( "../Documents" );
}
static int deforient = -1;
/*!
\internal
*/
int QPEApplication::defaultRotation()
{
if ( deforient < 0 ) {
QString d = getenv( "QWS_DISPLAY" );
if ( d.contains( "Rot90" ) ) {
deforient = 90;
}
else if ( d.contains( "Rot180" ) ) {
deforient = 180;
}
else if ( d.contains( "Rot270" ) ) {
deforient = 270;
}
else {
deforient = 0;
}
}
return deforient;
}
/*!
\internal
*/
void QPEApplication::setDefaultRotation( int r )
{
if ( qApp->type() == GuiServer ) {
deforient = r;
setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
Config config("qpe");
config.setGroup( "Rotation" );
config.writeEntry( "Rot", r );
}
else {
#ifndef QT_NO_COP
{ QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
e << r;
}
#endif
}
}
#include <qgfx_qws.h>
#include <qwindowsystem_qws.h>
-#include <qpixmapcache.h>
extern void qws_clearLoadedFonts();
void QPEApplication::setCurrentMode( int x, int y, int depth )
{
// Reset the caches
qws_clearLoadedFonts();
QPixmapCache::clear();
// Change the screen mode
qt_screen->setMode(x, y, depth);
if ( qApp->type() == GuiServer ) {
// Reconfigure the GuiServer
qwsServer->beginDisplayReconfigure();
qwsServer->endDisplayReconfigure();
// Get all the running apps to reset
QCopEnvelope env( "QPE/System", "reset()" );
}
}
void QPEApplication::reset() {
// Reconnect to the screen
qt_screen->disconnect();
qt_screen->connect( QString::null );
// Redraw everything
applyStyle();
}
/*!
\internal
*/
void QPEApplication::applyStyle()
{
Config config( "qpe" );
config.setGroup( "Appearance" );
#if QT_VERSION > 233
#if !defined(OPIE_NO_OVERRIDE_QT)
// don't block ourselves ...
Opie::force_appearance = 0;
static QString appname = Opie::binaryName ( );
QStringList ex = config. readListEntry ( "NoStyle", ';' );
int nostyle = 0;
for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
break;
}
}
#else
int nostyle = 0;
#endif
// Widget style
QString style = config.readEntry( "Style", "FlatStyle" );
// don't set a custom style
if ( nostyle & Opie::Force_Style )
style = "FlatStyle";
internalSetStyle ( style );
// Colors - from /etc/colors/Liquid.scheme
QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
QPalette pal( btncolor, bgcolor );
QString color = config.readEntry( "Highlight", "#73adef" );
pal.setColor( QColorGroup::Highlight, QColor( color ) );
color = config.readEntry( "HighlightedText", "#FFFFFF" );
pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
color = config.readEntry( "Text", "#000000" );
pal.setColor( QColorGroup::Text, QColor( color ) );
color = config.readEntry( "ButtonText", "#000000" );
pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
color = config.readEntry( "Base", "#FFFFFF" );
pal.setColor( QColorGroup::Base, QColor( color ) );
pal.setColor( QPalette::Disabled, QColorGroup::Text,
pal.color( QPalette::Active, QColorGroup::Background ).dark() );
setPalette( pal, TRUE );
// Window Decoration
QString dec = config.readEntry( "Decoration", "Flat" );
// don't set a custom deco
if ( nostyle & Opie::Force_Decoration )
dec = "";
//qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
if ( dec != d->decorationName ) {
qwsSetDecoration( new QPEDecoration( dec ) );
d->decorationName = dec;
}
// Font
QString ff = config.readEntry( "FontFamily", font().family() );
int fs = config.readNumEntry( "FontSize", font().pointSize() );
// don't set a custom font
if ( nostyle & Opie::Force_Font ) {
ff = "Vera";
fs = 10;
}
setFont ( QFont ( ff, fs ), true );
#if !defined(OPIE_NO_OVERRIDE_QT)
// revert to global blocking policy ...
Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
Opie::force_appearance &= ~nostyle;
#endif
#endif
}
void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
{
#ifdef Q_WS_QWS
QDataStream stream( data, IO_ReadOnly );
if ( msg == "applyStyle()" ) {
applyStyle();
}
else if ( msg == "toggleApplicationMenu()" ) {
QWidget *active = activeWindow ( );
if ( active ) {
QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
bool oldactive = man-> isActive ( );
man-> setActive( !man-> isActive() );
if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
}
}
}
else if ( msg == "setDefaultRotation(int)" ) {
if ( type() == GuiServer ) {
int r;
stream >> r;
setDefaultRotation( r );
}
}
else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
if ( type() == GuiServer ) {
int x, y, depth;
stream >> x;
stream >> y;
stream >> depth;
setCurrentMode( x, y, depth );
}
}
else if ( msg == "reset()" ) {
if ( type() != GuiServer )
reset();
}
else if ( msg == "setCurrentRotation(int)" ) {
int r;
stream >> r;
setCurrentRotation( r );
}
else if ( msg == "shutdown()" ) {
if ( type() == GuiServer )
shutdown();
}
else if ( msg == "quit()" ) {
if ( type() != GuiServer )
tryQuit();
}
else if ( msg == "forceQuit()" ) {
if ( type() != GuiServer )
quit();
}
else if ( msg == "restart()" ) {
if ( type() == GuiServer )
restart();
}
else if ( msg == "language(QString)" ) {
if ( type() == GuiServer ) {
QString l;
stream >> l;
QString cl = getenv( "LANG" );
if ( cl != l ) {
if ( l.isNull() )
unsetenv( "LANG" );
else
setenv( "LANG", l.latin1(), 1 );
restart();
}
}
}
else if ( msg == "timeChange(QString)" ) {
QString t;
stream >> t;
if ( t.isNull() )
unsetenv( "TZ" );
else
setenv( "TZ", t.latin1(), 1 );
// emit the signal so everyone else knows...
emit timeChanged();
}
else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
if ( type() == GuiServer ) {
QDateTime when;
QCString channel, message;
int data;
stream >> when >> channel >> message >> data;
AlarmServer::addAlarm( when, channel, message, data );
}
}
else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
if ( type() == GuiServer ) {
QDateTime when;
QCString channel, message;
int data;
stream >> when >> channel >> message >> data;
AlarmServer::deleteAlarm( when, channel, message, data );
}
}
else if ( msg == "clockChange(bool)" ) {
int tmp;
stream >> tmp;
emit clockChanged( tmp );
}
else if ( msg == "weekChange(bool)" ) {
int tmp;
stream >> tmp;
emit weekChanged( tmp );
}
else if ( msg == "setDateFormat(DateFormat)" ) {
DateFormat tmp;
stream >> tmp;
emit dateFormatChanged( tmp );
}
else if ( msg == "setVolume(int,int)" ) {
int t, v;
stream >> t >> v;
setVolume( t, v );
emit volumeChanged( muted );
}
else if ( msg == "volumeChange(bool)" ) {
stream >> muted;
setVolume();
emit volumeChanged( muted );
}
else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
int t, v;
stream >> t >> v;
setMic( t, v );
emit micChanged( micMuted );
}
else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
stream >> micMuted;
setMic();
emit micChanged( micMuted );
}
else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
int t, v;
stream >> t >> v;
setBass( t, v );
}
else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
setBass();
}
else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
int t, v;
stream >> t >> v;
setTreble( t, v );
}
else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
setTreble();
} else if ( msg == "getMarkedText()" ) {
if ( type() == GuiServer ) {
const ushort unicode = 'C'-'@';
const int scan = Key_C;
qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
}
} else if ( msg == "newChannel(QString)") {
QString myChannel = "QPE/Application/" + d->appName;
QString channel;
stream >> channel;
if (channel == myChannel) {
processQCopFile();
d->sendQCopQ();
}
}
#endif
}
/*!
\internal
*/
bool QPEApplication::raiseAppropriateWindow()
{
bool r=FALSE;
// 1. Raise the main widget
QWidget *top = d->qpe_main_widget;
if ( !top ) top = mainWidget();
if ( top && d->keep_running ) {
if ( top->isVisible() )
r = TRUE;
else if (d->preloaded) {
// We are preloaded and not visible.. pretend we just started..
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
e << d->appName;
#endif
}
d->show_mx(top,d->nomaximize, d->appName);
top->raise();
}
QWidget *topm = activeModalWidget();
// 2. Raise any parentless widgets (except top and topm, as they
// are raised before and after this loop). Order from most
// recently raised as deepest to least recently as top, so
// that repeated calls cycle through widgets.
QWidgetList *list = topLevelWidgets();
if ( list ) {
bool foundlast = FALSE;
QWidget* topsub = 0;
if ( d->lastraised ) {
for (QWidget* w = list->first(); w; w = list->next()) {
if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
if ( w == d->lastraised )
foundlast = TRUE;
if ( foundlast ) {
w->raise();
topsub = w;
}
}
}
}
for (QWidget* w = list->first(); w; w = list->next()) {
if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
if ( w == d->lastraised )
break;
w->raise();
topsub = w;
}
}
d->lastraised = topsub;
delete list;
}
// 3. Raise the active modal widget.
if ( topm && topm != top ) {
topm->show();
topm->raise();
// If we haven't already handled the fastAppShowing message
if (!top && d->preloaded) {
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
e << d->appName;
#endif
}
r = FALSE;
}
return r;
}
void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
{
#ifdef Q_WS_QWS
if ( msg == "quit()" ) {
tryQuit();
}
else if ( msg == "quitIfInvisible()" ) {
if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
quit();
}
else if ( msg == "close()" ) {
hideOrQuit();
}
else if ( msg == "disablePreload()" ) {
d->preloaded = FALSE;
d->keep_running = TRUE;
/* so that quit will quit */
}
else if ( msg == "enablePreload()" ) {
if (d->qpe_main_widget)
d->preloaded = TRUE;
d->keep_running = TRUE;
/* so next quit won't quit */
}
else if ( msg == "raise()" ) {
d->keep_running = TRUE;
d->notbusysent = FALSE;
raiseAppropriateWindow();
// Tell the system we're still chugging along...
QCopEnvelope e("QPE/System", "appRaised(QString)");
e << d->appName;
}
else if ( msg == "flush()" ) {
emit flush();
// we need to tell the desktop
QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
e << d->appName;
}
else if ( msg == "reload()" ) {
emit reload();
}
else if ( msg == "setDocument(QString)" ) {
d->keep_running = TRUE;
QDataStream stream( data, IO_ReadOnly );
QString doc;
stream >> doc;
QWidget *mw = mainWidget();
if ( !mw )
mw = d->qpe_main_widget;
if ( mw )
Global::setDocument( mw, doc );
} else if ( msg == "QPEProcessQCop()" ) {
processQCopFile();
d->sendQCopQ();
}else
{
bool p = d->keep_running;
d->keep_running = FALSE;
emit appMessage( msg, data);
if ( d->keep_running ) {
d->notbusysent = FALSE;
raiseAppropriateWindow();
if ( !p ) {
// Tell the system we're still chugging along...
#ifndef QT_NO_COP
QCopEnvelope e("QPE/System", "appRaised(QString)");
e << d->appName;
#endif
}
}
if ( p )
d->keep_running = p;
}
#endif
}
/*!
Sets widget \a mw as the mainWidget() and shows it. For small windows,
consider passing TRUE for \a nomaximize rather than the default FALSE.
\sa showMainDocumentWidget()
*/
void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
{
// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
d->show(mw, nomaximize );
}
/*!
Sets widget \a mw as the mainWidget() and shows it. For small windows,
consider passing TRUE for \a nomaximize rather than the default FALSE.
This calls designates the application as
a \link docwidget.html document-oriented\endlink application.
The \a mw widget \e must have this slot: setDocument(const QString&).
\sa showMainWidget()
*/
void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
{
if ( mw && argc() == 2 )
Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
// setMainWidget(mw); see above
d->show(mw, nomaximize );
}
/*!
If an application is started via a \link qcop.html QCop\endlink
message, the application will process the \link qcop.html
QCop\endlink message and then quit. If the application calls this
function while processing a \link qcop.html QCop\endlink message,
after processing its outstanding \link qcop.html QCop\endlink
messages the application will start 'properly' and show itself.
\sa keepRunning()
*/
void QPEApplication::setKeepRunning()
{
if ( qApp && qApp->inherits( "QPEApplication" ) ) {
QPEApplication * qpeApp = ( QPEApplication* ) qApp;
qpeApp->d->keep_running = TRUE;
}
}
/*!
Returns TRUE if the application will quit after processing the
current list of qcop messages; otherwise returns FALSE.
\sa setKeepRunning()
*/
bool QPEApplication::keepRunning() const
{
return d->keep_running;
}
/*!
\internal
*/
void QPEApplication::internalSetStyle( const QString &style )
{
#if QT_VERSION >= 300
if ( style == "QPE" ) {
setStyle( new QPEStyle );
}
else {
QStyle *s = QStyleFactory::create( style );
if ( s )
setStyle( s );
}
#else
if ( style == "Windows" ) {
setStyle( new QWindowsStyle );
}
else if ( style == "QPE" ) {
setStyle( new QPEStyle );
}
else if ( style == "Light" ) {
setStyle( new LightStyle );
}
#ifndef QT_NO_STYLE_PLATINUM
else if ( style == "Platinum" ) {
setStyle( new QPlatinumStyle );
}
#endif
#ifndef QT_NO_STYLE_MOTIF
else if ( style == "Motif" ) {
setStyle( new QMotifStyle );
}
#endif
#ifndef QT_NO_STYLE_MOTIFPLUS
else if ( style == "MotifPlus" ) {
setStyle( new QMotifPlusStyle );
}
#endif
else {
QStyle *sty = 0;
QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
#ifdef Q_OS_MACX
if ( style. find ( ".dylib" ) > 0 )
path += style;
else
path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
#else
if ( style. find ( ".so" ) > 0 )
path += style;
else
path = path + "lib" + style. lower ( ) + ".so"; // compatibility
#endif
static QLibrary *lastlib = 0;
static StyleInterface *lastiface = 0;
QLibrary *lib = new QLibrary ( path );
StyleInterface *iface = 0;
if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
sty = iface-> style ( );
if ( sty ) {
setStyle ( sty );
if ( lastiface )
lastiface-> release ( );
lastiface = iface;
if ( lastlib ) {
lastlib-> unload ( );
delete lastlib;
}
lastlib = lib;
}
else {
if ( iface )
iface-> release ( );
delete lib;
setStyle ( new LightStyle ( ));
}
}
#endif
}
/*!
\internal
*/
void QPEApplication::prepareForTermination( bool willrestart )
{
if ( willrestart ) {
// Draw a big wait icon, the image can be altered in later revisions
// QWidget *d = QApplication::desktop();
QImage img = Resource::loadImage( "launcher/new_wait" );
QPixmap pix;
pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
lblWait->setPixmap( pix );
lblWait->setAlignment( QWidget::AlignCenter );
lblWait->show();
lblWait->showMaximized();
}
#ifndef SINGLE_APP
{ QCopEnvelope envelope( "QPE/System", "forceQuit()" );
}
processEvents(); // ensure the message goes out.
sleep( 1 ); // You have 1 second to comply.
#endif
}
/*!
\internal
*/
void QPEApplication::shutdown()
{
// Implement in server's QPEApplication subclass
}
/*!
\internal
*/
void QPEApplication::restart()
{
// Implement in server's QPEApplication subclass
}
static QPtrDict<void>* stylusDict = 0;
static void createDict()
{
if ( !stylusDict )
stylusDict = new QPtrDict<void>;
}
/*!
Returns the current StylusMode for widget \a w.
\sa setStylusOperation() StylusMode
*/
QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
{
if ( stylusDict )
return ( StylusMode ) ( int ) stylusDict->find( w );
return LeftOnly;
}
/*!
\enum QPEApplication::StylusMode
\value LeftOnly the stylus only generates LeftButton
events (the default).
\value RightOnHold the stylus generates RightButton events
if the user uses the press-and-hold gesture.
\sa setStylusOperation() stylusOperation()
*/
/*!
Causes widget \a w to receive mouse events according to the stylus
\a mode.
\sa stylusOperation() StylusMode
*/
void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
{
createDict();
if ( mode == LeftOnly ) {
stylusDict->remove
( w );
w->removeEventFilter( qApp );
}
else {
stylusDict->insert( w, ( void* ) mode );
connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
w->installEventFilter( qApp );
}
}
/*!
\reimp
*/
bool QPEApplication::eventFilter( QObject *o, QEvent *e )
{
if ( !o->isWidgetType() )
return FALSE;
if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
QMouseEvent * me = ( QMouseEvent* ) e;
StylusMode mode = (StylusMode)(int)stylusDict->find(o);
switch (mode) {
case RightOnHold:
switch ( me->type() ) {
case QEvent::MouseButtonPress:
if ( me->button() == LeftButton ) {
if (!d->presstimer )
d->presstimer = startTimer(500); // #### pref.
d->presswidget = (QWidget*)o;
d->presspos = me->pos();
d->rightpressed = FALSE;
}
break;
case QEvent::MouseMove:
if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
killTimer(d->presstimer);
d->presstimer = 0;
}
break;
case QEvent::MouseButtonRelease:
if ( me->button() == LeftButton ) {
if ( d->presstimer ) {
killTimer(d->presstimer);
d->presstimer = 0;
}
if ( d->rightpressed && d->presswidget ) {
// Right released
postEvent( d->presswidget,
new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
RightButton, LeftButton + RightButton ) );
// Left released, off-widget
postEvent( d->presswidget,
new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
LeftButton, LeftButton ) );
postEvent( d->presswidget,
new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
LeftButton, LeftButton ) );
d->rightpressed = FALSE;
return TRUE; // don't send the real Left release
}
}
break;
default:
break;
}
break;
default:
;
}
}
else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
QKeyEvent *ke = (QKeyEvent *)e;
if ( ke->key() == Key_Enter ) {
if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
return TRUE;
}
}
}
return FALSE;
}
/*!
\reimp
*/
void QPEApplication::timerEvent( QTimerEvent *e )
{
if ( e->timerId() == d->presstimer && d->presswidget ) {
// Right pressed
postEvent( d->presswidget,
new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
RightButton, LeftButton ) );
killTimer( d->presstimer );
d->presstimer = 0;
d->rightpressed = TRUE;
}
}
void QPEApplication::removeSenderFromStylusDict()
{
stylusDict->remove
( ( void* ) sender() );
if ( d->presswidget == sender() )
d->presswidget = 0;
}
/*!
\internal
*/
bool QPEApplication::keyboardGrabbed() const
{
return d->kbgrabbed;
}
/*!
Reverses the effect of grabKeyboard(). This is called automatically
on program exit.
*/
void QPEApplication::ungrabKeyboard()
{
((QPEApplication *) qApp )-> d-> kbgrabbed = false;
}
/*!
Grabs the physical keyboard keys, e.g. the application's launching
keys. Instead of launching applications when these keys are pressed
the signals emitted are sent to this application instead. Some games
programs take over the launch keys in this way to make interaction
easier.
\sa ungrabKeyboard()
*/
void QPEApplication::grabKeyboard()
{
((QPEApplication *) qApp )-> d-> kbgrabbed = true;
}
/*!
\reimp
*/
int QPEApplication::exec()
{
d->qcopQok = true;
#ifndef QT_NO_COP
d->sendQCopQ();
if ( !d->keep_running )
processEvents(); // we may have received QCop messages in the meantime.
#endif
if ( d->keep_running )
//|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
return QApplication::exec();
#ifndef QT_NO_COP
{
QCopEnvelope e( "QPE/System", "closing(QString)" );
e << d->appName;
}
#endif
processEvents();
return 0;
}
/*!
\internal
External request for application to quit. Quits if possible without
loosing state.
*/
void QPEApplication::tryQuit()
{
if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
return ; // Inside modal loop or konsole. Too hard to save state.
#ifndef QT_NO_COP
{
QCopEnvelope e( "QPE/System", "closing(QString)" );
e << d->appName;
}
#endif
processEvents();
quit();
}
/*!
\internal
*/
void QPEApplication::installTranslation( const QString& baseName ) {
QTranslator* trans = new QTranslator(this);
QString tfn = qpeDir() + "/i18n/"+baseName;
if ( trans->load( tfn ) )
installTranslator( trans );
else
delete trans;
}
/*!
\internal
User initiated quit. Makes the window 'Go Away'. If preloaded this means
hiding the window. If not it means quitting the application.
As this is user initiated we don't need to check state.
*/
void QPEApplication::hideOrQuit()
{
processEvents();
// If we are a preloaded application we don't actually quit, so emit
// a System message indicating we're quasi-closing.
if ( d->preloaded && d->qpe_main_widget )
#ifndef QT_NO_COP
{
QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
e << d->appName;
d->qpe_main_widget->hide();
}
#endif
else
quit();
}
#if (__GNUC__ > 2 )
extern "C" void __cxa_pure_virtual();
void __cxa_pure_virtual()
{
fprintf( stderr, "Pure virtual called\n");
abort();
}
#endif
#if defined(OPIE_NEW_MALLOC)
// The libraries with the skiff package (and possibly others) have
// completely useless implementations of builtin new and delete that
// use about 50% of your CPU. Here we revert to the simple libc
// functions.
void* operator new[]( size_t size )
{
return malloc( size );
}
void* operator new( size_t size )
{
return malloc( size );
}
void operator delete[]( void* p )
{
free( p );
}
void operator delete[]( void* p, size_t /*size*/ )
{
free( p );
}
void operator delete( void* p )
{
free( p );
}
void operator delete( void* p, size_t /*size*/ )
{
free( p );
}
#endif
#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
#include <qwidgetlist.h>
#ifdef QWS
#include <qgfx_qws.h>
extern QRect qt_maxWindowRect;
void qt_setMaxWindowRect(const QRect& r )
{
qt_maxWindowRect = qt_screen->mapFromDevice( r,
qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
// Re-resize any maximized windows
QWidgetList* l = QApplication::topLevelWidgets();
if ( l ) {
QWidget * w = l->first();
while ( w ) {
if ( w->isVisible() && w->isMaximized() ) {
w->showMaximized();
}
w = l->next();
}
delete l;
}
}
#endif
#endif
diff --git a/library/qpemenubar.cpp b/library/qpemenubar.cpp
index 3e5bad5..1d8eff4 100644
--- a/library/qpemenubar.cpp
+++ b/library/qpemenubar.cpp
@@ -1,330 +1,329 @@
/**********************************************************************
** 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 INCLUDE_MENUITEM_DEF
#include "qpemenubar.h"
#include <qapplication.h>
-#include <qguardedptr.h>
#include <qtimer.h>
class QMenuBarHack : public QMenuBar
{
public:
int activeItem() const { return actItem; }
void goodbye()
{
activateItemAt(-1);
for ( unsigned int i = 0; i < count(); i++ ) {
QMenuItem *mi = findItem( idAt(i) );
if ( mi->popup() ) {
mi->popup()->hide();
}
}
}
};
// Sharp ROM compatibility
void QPEMenuToolFocusManager::setMenukeyEnabled ( bool )
{
}
int QPEMenuBar::getOldFocus ( )
{
return 0;
}
QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0;
QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject()
{
qApp->installEventFilter( this );
}
void QPEMenuToolFocusManager::addWidget( QWidget *w )
{
list.append( GuardedWidget(w) );
}
void QPEMenuToolFocusManager::removeWidget( QWidget *w )
{
list.remove( GuardedWidget(w) );
}
void QPEMenuToolFocusManager::setActive( bool a )
{
if ( a ) {
oldFocus = qApp->focusWidget();
QValueList<GuardedWidget>::Iterator it;
it = list.begin();
while ( it != list.end() ) {
QWidget *w = (*it);
if ( w && w->isEnabled() && w->isVisible() &&
w->topLevelWidget() == qApp->activeWindow() ) {
setFocus( w );
return;
}
++it;
}
} else {
if ( inFocus ) {
if ( inFocus->inherits( "QMenuBar" ) )
((QMenuBarHack *)(QWidget *)inFocus)->goodbye();
if ( inFocus->hasFocus() ) {
if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) {
oldFocus->setFocus();
} else {
inFocus->clearFocus();
}
}
}
inFocus = 0;
oldFocus = 0;
}
}
bool QPEMenuToolFocusManager::isActive() const
{
return !inFocus.isNull();
}
void QPEMenuToolFocusManager::moveFocus( bool next )
{
if ( !isActive() )
return;
int n = list.count();
QValueList<GuardedWidget>::Iterator it;
it = list.find( inFocus );
if ( it == list.end() )
it = list.begin();
while ( --n ) {
if ( next ) {
++it;
if ( it == list.end() )
it = list.begin();
} else {
if ( it == list.begin() )
it = list.end();
--it;
}
QWidget *w = (*it);
if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") &&
w->topLevelWidget() == qApp->activeWindow() ) {
setFocus( w, next );
return;
}
}
}
void QPEMenuToolFocusManager::initialize()
{
if ( !me )
me = new QPEMenuToolFocusManager;
}
QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager()
{
if ( !me )
me = new QPEMenuToolFocusManager;
return me;
}
void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next )
{
inFocus = w;
// qDebug( "Set focus on %s", w->className() );
if ( inFocus->inherits( "QMenuBar" ) ) {
QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus;
if ( next )
mb->activateItemAt( 0 );
else
mb->activateItemAt( mb->count()-1 );
}
inFocus->setFocus();
}
bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event )
{
if ( event->type() == QEvent::KeyPress ) {
QKeyEvent *ke = (QKeyEvent *)event;
if ( isActive() ) {
if ( object->inherits( "QButton" ) ) {
switch ( ke->key() ) {
case Key_Left:
moveFocus( FALSE );
return TRUE;
case Key_Right:
moveFocus( TRUE );
return TRUE;
case Key_Up:
case Key_Down:
return TRUE;
}
} else if ( object->inherits( "QPopupMenu" ) ) {
// Deactivate when a menu item is selected
if ( ke->key() == Key_Enter || ke->key() == Key_Return ||
ke->key() == Key_Escape ) {
QTimer::singleShot( 0, this, SLOT(deactivate()) );
}
} else if ( object->inherits( "QMenuBar" ) ) {
int dx = 0;
switch ( ke->key() ) {
case Key_Left:
dx = -1;
break;
case Key_Right:
dx = 1;
break;
}
QMenuBarHack *mb = (QMenuBarHack *)object;
if ( dx && mb->activeItem() >= 0 ) {
int i = mb->activeItem();
int c = mb->count();
int n = c;
while ( n-- ) {
i = i + dx;
if ( i == c ) {
mb->goodbye();
moveFocus( TRUE );
return TRUE;
} else if ( i < 0 ) {
mb->goodbye();
moveFocus( FALSE );
return TRUE;
}
QMenuItem *mi = mb->findItem( mb->idAt(i) );
if ( mi->isEnabled() && !mi->isSeparator() ) {
break;
}
}
}
}
}
} else if ( event->type() == QEvent::KeyRelease ) {
QKeyEvent *ke = (QKeyEvent *)event;
if ( isActive() ) {
if ( object->inherits( "QButton" ) ) {
// Deactivate when a button is selected
if ( ke->key() == Key_Space )
QTimer::singleShot( 0, this, SLOT(deactivate()) );
}
}
} else if ( event->type() == QEvent::FocusIn ) {
if ( isActive() ) {
// A non-menu/tool widget has been selected - we're deactivated
QWidget *w = (QWidget *)object;
if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) {
inFocus = 0;
}
}
} else if ( event->type() == QEvent::Hide ) {
if ( isActive() ) {
// Deaticvate if a menu/tool has been hidden
QWidget *w = (QWidget *)object;
if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) {
setActive( FALSE );
}
}
} else if ( event->type() == QEvent::ChildInserted ) {
QChildEvent *ce = (QChildEvent *)event;
if ( ce->child()->isWidgetType() ) {
if ( ce->child()->inherits( "QMenuBar" ) ) {
addWidget( (QWidget *)ce->child() );
ce->child()->installEventFilter( this );
} else if ( object->inherits( "QToolBar" ) ) {
addWidget( (QWidget *)ce->child() );
}
}
} else if ( event->type() == QEvent::ChildRemoved ) {
QChildEvent *ce = (QChildEvent *)event;
if ( ce->child()->isWidgetType() ) {
if ( ce->child()->inherits( "QMenuBar" ) ) {
removeWidget( (QWidget *)ce->child() );
ce->child()->removeEventFilter( this );
} else if ( object->inherits( "QToolBar" ) ) {
removeWidget( (QWidget *)ce->child() );
}
}
}
return FALSE;
}
void QPEMenuToolFocusManager::deactivate()
{
setActive( FALSE );
}
/*!
\class QPEMenuBar qpemenubar.h
\brief The QPEMenuBar class is obsolete. Use QMenuBar instead.
\obsolete
This class is obsolete. Use QMenuBar instead.
*/
/*!
Constructs a QPEMenuBar just as you would construct
a QMenuBar, passing \a parent and \a name.
*/
QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name )
: QMenuBar( parent, name )
{
}
/*!
\reimp
*/
QPEMenuBar::~QPEMenuBar()
{
}
/*!
\internal
*/
void QPEMenuBar::keyPressEvent( QKeyEvent *e )
{
QMenuBar::keyPressEvent( e );
}
/*!
\internal
*/
void QPEMenuBar::activateItem( int index ) {
activateItemAt( index );
}
void QPEMenuBar::goodbye() {
activateItemAt(-1);
for ( uint i = 0; i < count(); i++ ) {
QMenuItem* mi = findItem( idAt(i) );
if (mi->popup() )
mi->popup()->hide();
}
}
diff --git a/library/qpestyle.cpp b/library/qpestyle.cpp
index 665910c..b61ada4 100644
--- a/library/qpestyle.cpp
+++ b/library/qpestyle.cpp
@@ -1,1194 +1,1191 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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 "qpestyle.h"
-#include <qpe/qpeapplication.h>
-#include <qpushbutton.h>
-#include <qpainter.h>
#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
#if QT_VERSION >= 300
#include <qdrawutil.h>
#include <qcombobox.h>
#include <qtabbar.h>
QPEStyle::QPEStyle()
{
}
QPEStyle::~QPEStyle()
{
}
void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
{
switch ( pe ) {
case PE_ButtonTool:
{
QColorGroup mycg = cg;
if ( flags & Style_On ) {
QBrush fill( cg.mid(), Dense4Pattern );
mycg.setBrush( QColorGroup::Button, fill );
}
drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
break;
}
case PE_ButtonCommand:
case PE_ButtonDefault:
case PE_ButtonBevel:
case PE_HeaderSection:
{
QPen oldPen = p->pen();
p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
int x2 = r.right();
int y2 = r.bottom();
if ( flags & (Style_Sunken | Style_Down | Style_On) )
p->setPen( cg.dark() );
else
p->setPen( cg.light() );
p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
if ( flags & (Style_Sunken | Style_Down | Style_On) )
p->setPen( cg.light() );
else
p->setPen( cg.dark() );
p->drawLine( x2, r.y()+1, x2, y2-1 );
p->drawLine( r.x()+1, y2, x2-1, y2 );
p->setPen( oldPen );
break;
}
case PE_FocusRect:
break;
case PE_Indicator:
{
QColorGroup mycg( cg );
QBrush fill;
if ( flags & Style_Down )
fill = cg.brush( QColorGroup::Button );
else
fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
mycg.setBrush( QColorGroup::Button, fill );
if ( flags&Style_Enabled )
flags |= Style_Sunken;
drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
if ( flags & Style_On ) {
QPointArray a( 7*2 );
int i, xx, yy;
xx = r.x()+3;
yy = r.y()+5;
for ( i=0; i<3; i++ ) {
a.setPoint( 2*i, xx, yy );
a.setPoint( 2*i+1, xx, yy+2 );
xx++; yy++;
}
yy -= 2;
for ( i=3; i<7; i++ ) {
a.setPoint( 2*i, xx, yy );
a.setPoint( 2*i+1, xx, yy+2 );
xx++; yy--;
}
if ( flags & Style_NoChange ) {
p->setPen( mycg.dark() );
} else {
p->setPen( mycg.text() );
}
p->drawLineSegments( a );
}
break;
}
case PE_ExclusiveIndicator:
{
static const QCOORD pts1[] = { // dark lines
1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
static const QCOORD pts4[] = { // white lines
2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
11,4, 10,3, 10,2 };
static const QCOORD pts5[] = { // inner fill
4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
int x, y, w, h;
r.rect( &x, &y, &w, &h );
p->eraseRect( x, y, w, h );
QPointArray a( QCOORDARRLEN(pts1), pts1 );
a.translate( x, y );
p->setPen( cg.dark() );
p->drawPolyline( a );
a.setPoints( QCOORDARRLEN(pts4), pts4 );
a.translate( x, y );
p->setPen( cg.light() );
p->drawPolyline( a );
a.setPoints( QCOORDARRLEN(pts5), pts5 );
a.translate( x, y );
QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
p->setPen( fillColor );
p->setBrush( fillColor ) ;
p->drawPolygon( a );
if ( flags&Style_On ) {
p->setPen( NoPen );
p->setBrush( cg.text() );
p->drawRect( x+5, y+4, 2, 4 );
p->drawRect( x+4, y+5, 4, 2 );
}
break;
}
default:
QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
break;
}
}
void QPEStyle::drawControl( ControlElement ce, QPainter *p,
const QWidget *widget, const QRect &r,
const QColorGroup &cg, SFlags how, const QStyleOption &data) const
{
switch ( ce ) {
case CE_PushButton:
{
const QPushButton *btn = (QPushButton*)widget;
SFlags flags;
flags = Style_Default;
if ( btn->isDown() )
flags |= Style_Down;
if ( btn->isOn() )
flags |= Style_On;
if ( btn->isEnabled() )
flags |= Style_Enabled;
if ( btn->isDefault() )
flags |= Style_Default;
if (! btn->isFlat() && !(flags & Style_Down))
flags |= Style_Raised;
p->setPen( cg.foreground() );
p->setBrush( QBrush(cg.button(), NoBrush) );
QColorGroup mycg( cg );
if ( flags & Style_On ) {
QBrush fill = QBrush( cg.mid(), Dense4Pattern );
mycg.setBrush( QColorGroup::Button, fill );
}
drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
break;
}
case CE_TabBarTab:
{
if ( !widget || !widget->parentWidget() )
break;
const QTabBar *tb = (const QTabBar *) widget;
bool selected = how & Style_Selected;
QRect r2(r);
if ( tb->shape() == QTabBar::RoundedAbove ) {
p->setPen( cg.light() );
p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
if ( r2.left() == 0 )
p->drawPoint( tb->rect().bottomLeft() );
else {
p->setPen( cg.light() );
p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
}
if ( selected ) {
p->setPen( cg.background() );
p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
cg.brush( QColorGroup::Background ));
} else {
r2.setRect( r2.left() + 2, r2.top() + 2,
r2.width() - 4, r2.height() - 2 );
p->setPen( cg.button() );
p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3),
cg.brush( QColorGroup::Button ));
//do shading; will not work for pixmap brushes
QColor bg = cg.button();
// int h,s,v;
// bg.hsv( &h, &s, &v );
int n = r2.height()/2;
int dark = 100;
for ( int i = 1; i < n; i++ ) {
dark = (dark * (100+(i*15)/n) )/100;
p->setPen( bg.dark( dark ) );
int y = r2.bottom()-n+i;
int x1 = r2.left()+1;
int x2 = r2.right()-1;
p->drawLine( x1, y, x2, y );
}
}
p->setPen( cg.light() );
p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
p->drawPoint( r2.left()+1, r2.top() + 1 );
p->drawLine( r2.left()+2, r2.top(),
r2.right() - 2, r2.top() );
p->setPen( cg.dark() );
p->drawPoint( r2.right() - 1, r2.top() + 1 );
p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1);
} else if ( tb->shape() == QTabBar::RoundedBelow ) {
if ( selected ) {
p->setPen( cg.background() );
p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2),
tb->palette().normal().brush( QColorGroup::Background ));
} else {
p->setPen( cg.dark() );
p->drawLine( r2.left(), r2.top(),
r2.right(), r2.top() );
r2.setRect( r2.left() + 2, r2.top(),
r2.width() - 4, r2.height() - 2 );
p->setPen( cg.button() );
p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3),
tb->palette().normal().brush( QColorGroup::Button ));
}
p->setPen( cg.dark() );
p->drawLine( r2.right(), r2.top(),
r2.right(), r2.bottom() - 2 );
p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
p->drawLine( r2.right() - 2, r2.bottom(),
r2.left() + 2, r2.bottom() );
p->setPen( cg.light() );
p->drawLine( r2.left(), r2.top()+1,
r2.left(), r2.bottom() - 2 );
p->drawPoint( r2.left() + 1, r2.bottom() - 1 );
if ( r2.left() == 0 )
p->drawPoint( tb->rect().topLeft() );
} else {
QCommonStyle::drawControl( ce, p, widget, r, cg, how, data );
}
break;
}
default:
QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data );
break;
}
}
void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p,
const QWidget *widget, const QRect &r,
const QColorGroup &cg, SFlags how,
SCFlags sub, SCFlags subActive, const QStyleOption &data) const
{
switch ( control ) {
case CC_ComboBox:
if ( sub & SC_ComboBoxArrow ) {
SFlags flags = Style_Default;
drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data );
QRect ar =
QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
SC_ComboBoxArrow ), widget );
if ( subActive == SC_ComboBoxArrow ) {
p->setPen( cg.dark() );
p->setBrush( cg.brush( QColorGroup::Button ) );
p->drawRect( ar );
}
ar.addCoords( 2, 2, -2, -2 );
if ( widget->isEnabled() )
flags |= Style_Enabled;
if ( subActive & Style_Sunken ) {
flags |= Style_Sunken;
}
drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
}
if ( sub & SC_ComboBoxEditField ) {
const QComboBox * cb = (const QComboBox *) widget;
QRect re =
QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
SC_ComboBoxEditField ), widget );
if ( cb->hasFocus() && !cb->editable() )
p->fillRect( re.x(), re.y(), re.width(), re.height(),
cg.brush( QColorGroup::Highlight ) );
if ( cb->hasFocus() ) {
p->setPen( cg.highlightedText() );
p->setBackgroundColor( cg.highlight() );
} else {
p->setPen( cg.text() );
p->setBackgroundColor( cg.background() );
}
if ( cb->hasFocus() && !cb->editable() ) {
QRect re =
QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget );
drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight()));
}
}
break;
default:
QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how,
sub, subActive, data );
break;
}
}
int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
{
int ret;
switch( metric ) {
case PM_ButtonMargin:
ret = 2;
break;
case PM_DefaultFrameWidth:
ret = 1;
break;
case PM_ButtonDefaultIndicator:
ret = 2;
break;
case PM_ButtonShiftHorizontal:
case PM_ButtonShiftVertical:
ret = -1;
break;
case PM_IndicatorWidth:
ret = 15;
break;
case PM_IndicatorHeight:
ret = 13;
break;
case PM_ExclusiveIndicatorHeight:
case PM_ExclusiveIndicatorWidth:
ret = 15;
break;
case PM_ScrollBarExtent:
ret = 13;
break;
case PM_SliderLength:
ret = 12;
break;
default:
ret = QWindowsStyle::pixelMetric( metric, widget );
break;
}
return ret;
}
QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget,
const QSize &contentsSize, const QStyleOption &data) const
{
QSize sz(contentsSize);
switch ( contents ) {
case CT_PopupMenuItem:
{
if ( !widget || data.isDefault() )
break;
sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
sz = QSize( sz.width(), sz.height()-2 );
break;
}
default:
sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
break;
}
return sz;
}
#else
#include <qfontmetrics.h>
#include <qpalette.h>
#include <qdrawutil.h>
#include <qscrollbar.h>
#include <qbutton.h>
#include <qframe.h>
#include <qtabbar.h>
#define INCLUDE_MENUITEM_DEF
#include <qmenudata.h>
QPEStyle::QPEStyle()
{
#if QT_VERSION < 300
setButtonMargin(buttonMargin());
setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());
#endif
}
QPEStyle::~QPEStyle()
{
}
int QPEStyle::buttonMargin() const
{
return 2;
}
QSize QPEStyle::scrollBarExtent() const
{
return QSize(13,13);
}
void QPEStyle::polish ( QPalette & )
{
}
void QPEStyle::polish( QWidget *w )
{
if ( w->inherits( "QListBox" ) ||
w->inherits( "QListView" ) ||
w->inherits( "QPopupMenu" ) ||
w->inherits( "QSpinBox" ) ) {
QFrame *f = (QFrame *)w;
f->setFrameShape( QFrame::StyledPanel );
f->setLineWidth( 1 );
}
}
void QPEStyle::unPolish( QWidget *w )
{
if ( w->inherits( "QListBox" ) ||
w->inherits( "QListView" ) ||
w->inherits( "QPopupMenu" ) ||
w->inherits( "QSpinBox" ) ) {
QFrame *f = (QFrame *)w;
f->setFrameShape( QFrame::StyledPanel );
f->setLineWidth( 2 );
}
}
int QPEStyle::defaultFrameWidth() const
{
return 1;
}
void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
{
qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
}
void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken, const QBrush* fill )
{
QPen oldPen = p->pen();
if ( sunken )
p->setPen( g.dark() );
else
p->setPen( g.light() );
int x2 = x+w-1;
int y2 = y+h-1;
p->drawLine( x, y, x, y2 );
p->drawLine( x, y, x2, y );
if ( sunken )
p->setPen( g.light() );
else
p->setPen( g.dark() );
p->drawLine( x2, y, x2, y2 );
p->drawLine( x, y2, x2, y2 );
p->setPen( oldPen );
p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
}
void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
{
p->fillRect( x, y, w, h, color1 );
}
void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken, const QBrush* fill )
{
drawButton( p, x, y, w, h, g, sunken, fill );
}
QRect QPEStyle::comboButtonRect( int x, int y, int w, int h)
{
return QRect(x+1, y+1, w-2-14, h-2);
}
QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h)
{
return QRect(x+2, y+2, w-4-14, h-4);
}
void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, bool sunken,
bool /*editable*/,
bool enabled,
const QBrush *fill )
{
drawBevelButton( p, x, y, w, h, g, FALSE, fill );
drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
drawArrow( p, QStyle::DownArrow, sunken,
x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
&g.brush( QColorGroup::Button ) );
}
void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
int h, const QColorGroup & g, bool on, bool down, bool enabled )
{
static const QCOORD pts1[] = { // dark lines
1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
static const QCOORD pts4[] = { // white lines
2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
11,4, 10,3, 10,2 };
static const QCOORD pts5[] = { // inner fill
4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
p->eraseRect( x, y, w, h );
QPointArray a( QCOORDARRLEN(pts1), pts1 );
a.translate( x, y );
p->setPen( g.dark() );
p->drawPolyline( a );
a.setPoints( QCOORDARRLEN(pts4), pts4 );
a.translate( x, y );
p->setPen( g.light() );
p->drawPolyline( a );
a.setPoints( QCOORDARRLEN(pts5), pts5 );
a.translate( x, y );
QColor fillColor = ( down || !enabled ) ? g.button() : g.base();
p->setPen( fillColor );
p->setBrush( fillColor ) ;
p->drawPolygon( a );
if ( on ) {
p->setPen( NoPen );
p->setBrush( g.text() );
p->drawRect( x+5, y+4, 2, 4 );
p->drawRect( x+4, y+5, 4, 2 );
}
}
void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
const QColorGroup & g, int state, bool down, bool enabled )
{
QBrush fill;
if ( state == QButton::NoChange ) {
QBrush b = p->brush();
QColor c = p->backgroundColor();
p->setBackgroundMode( TransparentMode );
p->setBackgroundColor( green );
fill = QBrush(g.base(), Dense4Pattern);
p->setBackgroundColor( c );
p->setBrush( b );
} else if ( down )
fill = g.brush( QColorGroup::Button );
else
fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
drawPanel( p, x, y, w, h, g, TRUE, 1, &fill );
if ( state != QButton::Off ) {
QPointArray a( 7*2 );
int i, xx, yy;
xx = x+3;
yy = y+5;
for ( i=0; i<3; i++ ) {
a.setPoint( 2*i, xx, yy );
a.setPoint( 2*i+1, xx, yy+2 );
xx++; yy++;
}
yy -= 2;
for ( i=3; i<7; i++ ) {
a.setPoint( 2*i, xx, yy );
a.setPoint( 2*i+1, xx, yy+2 );
xx++; yy--;
}
if ( state == QButton::NoChange ) {
p->setPen( g.dark() );
} else {
p->setPen( g.text() );
}
p->drawLineSegments( a );
}
}
#define HORIZONTAL (sb->orientation() == QScrollBar::Horizontal)
#define VERTICAL !HORIZONTAL
#define MOTIF_BORDER 2
#define SLIDER_MIN 9 // ### motif says 6 but that's too small
/*! \reimp */
void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
{
int maxLength;
int length = HORIZONTAL ? sb->width() : sb->height();
int extent = HORIZONTAL ? sb->height() : sb->width();
if ( length > (extent - 1)*2 )
buttonDim = extent;
else
buttonDim = length/2 - 1;
sliderMin = 0;
maxLength = length - buttonDim*2;
if ( sb->maxValue() == sb->minValue() ) {
sliderLength = maxLength;
} else {
sliderLength = (sb->pageStep()*maxLength)/
(sb->maxValue()-sb->minValue()+sb->pageStep());
uint range = sb->maxValue()-sb->minValue();
if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
sliderLength = SLIDER_MIN;
if ( sliderLength > maxLength )
sliderLength = maxLength;
}
sliderMax = sliderMin + maxLength - sliderLength;
}
/*!\reimp
*/
QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
{
if ( !sb->rect().contains( p ) )
return NoScroll;
int sliderMin, sliderMax, sliderLength, buttonDim, pos;
scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
if (sb->orientation() == QScrollBar::Horizontal)
pos = p.x();
else
pos = p.y();
if (pos < sliderStart)
return SubPage;
if (pos < sliderStart + sliderLength)
return Slider;
if (pos < sliderMax + sliderLength)
return AddPage;
if (pos < sliderMax + sliderLength + buttonDim)
return SubLine;
return AddLine;
}
/*! \reimp */
void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
{
#define ADD_LINE_ACTIVE ( activeControl == AddLine )
#define SUB_LINE_ACTIVE ( activeControl == SubLine )
QColorGroup g = sb->colorGroup();
int sliderMin, sliderMax, sliderLength, buttonDim;
scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
if (sliderStart > sliderMax) { // sanity check
sliderStart = sliderMax;
}
int dimB = buttonDim;
QRect addB;
QRect subB;
QRect addPageR;
QRect subPageR;
QRect sliderR;
int addX, addY, subX, subY;
int length = HORIZONTAL ? sb->width() : sb->height();
int extent = HORIZONTAL ? sb->height() : sb->width();
if ( HORIZONTAL ) {
subY = addY = ( extent - dimB ) / 2;
subX = length - dimB - dimB;
addX = length - dimB;
} else {
subX = addX = ( extent - dimB ) / 2;
subY = length - dimB - dimB;
addY = length - dimB;
}
int sliderEnd = sliderStart + sliderLength;
int sliderW = extent;
if ( HORIZONTAL ) {
subB.setRect( subX,subY+1,dimB,dimB-1 );
addB.setRect( addX,addY+1,dimB,dimB-1 );
subPageR.setRect( 0, 0,
sliderStart+1, sliderW );
addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
} else {
subB.setRect( subX+1,subY,dimB-1,dimB );
addB.setRect( addX+1,addY,dimB-1,dimB );
subPageR.setRect( 0, 0, sliderW,
sliderStart+1 );
addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
}
bool maxedOut = (sb->maxValue() == sb->minValue());
if ( controls & AddLine ) {
drawBevelButton( p, addB.x(), addB.y(),
addB.width(), addB.height(), g,
ADD_LINE_ACTIVE);
p->setPen(g.shadow());
drawArrow( p, VERTICAL ? DownArrow : RightArrow,
FALSE, addB.x()+2, addB.y()+2,
addB.width()-4, addB.height()-4, g, !maxedOut,
&g.brush( QColorGroup::Button ));
}
if ( controls & SubLine ) {
drawBevelButton( p, subB.x(), subB.y(),
subB.width(), subB.height(), g,
SUB_LINE_ACTIVE );
p->setPen(g.shadow());
drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
FALSE, subB.x()+2, subB.y()+2,
subB.width()-4, subB.height()-4, g, !maxedOut,
&g.brush( QColorGroup::Button ));
}
if ( controls & SubPage )
p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
subPageR.height(), g.brush( QColorGroup::Mid ));
if ( controls & AddPage )
p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
addPageR.height(), g.brush( QColorGroup::Mid ));
if ( controls & Slider ) {
QPoint bo = p->brushOrigin();
p->setBrushOrigin(sliderR.topLeft());
drawBevelButton( p, sliderR.x(), sliderR.y(),
sliderR.width(), sliderR.height(), g,
FALSE, &g.brush( QColorGroup::Button ) );
p->setBrushOrigin(bo);
drawRiffles( p, sliderR.x(), sliderR.y(),
sliderR.width(), sliderR.height(), g, HORIZONTAL );
}
// ### perhaps this should not be able to accept focus if maxedOut?
if ( sb->hasFocus() && (controls & Slider) )
p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
sliderR.width()-5, sliderR.height()-5,
sb->backgroundColor() );
}
void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
const QColorGroup &g, bool horizontal )
{
if (!horizontal) {
if (h > 20) {
y += (h-20)/2 ;
h = 20;
}
if (h > 12) {
int n = 3;
int my = y+h/2-4;
int i ;
p->setPen(g.light());
for (i=0; i<n; i++) {
p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
}
p->setPen(g.dark());
my++;
for (i=0; i<n; i++) {
p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
}
}
}
else {
if (w > 20) {
x += (w-20)/2 ;
w = 20;
}
if (w > 12) {
int n = 3;
int mx = x+w/2-4;
int i ;
p->setPen(g.light());
for (i=0; i<n; i++) {
p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
}
p->setPen(g.dark());
mx++;
for (i=0; i<n; i++) {
p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
}
}
}
}
int QPEStyle::sliderLength() const
{
return 12;
}
void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
{
int a = tickAbove ? 3 : 0;
int b = tickBelow ? 3 : 0;
if ( o == Horizontal ) {
drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
int xp = x + w/2;
qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
} else {
drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
int yp = y + h/2;
qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
}
}
void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
Orientation o, bool tickAbove, bool tickBelow )
{
int a = tickAbove ? 3 : 0;
int b = tickBelow ? 3 : 0;
if ( o == Horizontal )
p->fillRect( x, y+a, w, h-a-b, color1 );
else
p->fillRect( x+a, y, w-a-b, h, color1 );
}
/*!\reimp
*/
void QPEStyle::drawSliderGrooveMask( QPainter *p,
int x, int y, int w, int h,
const QColorGroup& , QCOORD c,
Orientation orient )
{
if ( orient == Horizontal )
p->fillRect( x, y + c - 2, w, 4, color1 );
else
p->fillRect( x + c - 2, y, 4, h, color1 );
}
void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
{
QRect r( t->rect() );
if ( tb->shape() == QTabBar::RoundedAbove ) {
p->setPen( tb->colorGroup().light() );
p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
if ( r.left() == 0 )
p->drawPoint( tb->rect().bottomLeft() );
else {
p->setPen( tb->colorGroup().light() );
p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
}
if ( selected ) {
p->setPen( tb->colorGroup().background() );
p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
tb->colorGroup().brush( QColorGroup::Background ));
} else {
r.setRect( r.left() + 2, r.top() + 2,
r.width() - 4, r.height() - 2 );
p->setPen( tb->colorGroup().button() );
p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
tb->colorGroup().brush( QColorGroup::Button ));
//do shading; will not work for pixmap brushes
QColor bg = tb->colorGroup().button();
// int h,s,v;
// bg.hsv( &h, &s, &v );
int n = r.height()/2;
int dark = 100;
for ( int i = 1; i < n; i++ ) {
dark = (dark * (100+(i*15)/n) )/100;
p->setPen( bg.dark( dark ) );
int y = r.bottom()-n+i;
int x1 = r.left()+1;
int x2 = r.right()-1;
p->drawLine( x1, y, x2, y );
}
}
p->setPen( tb->colorGroup().light() );
p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
p->drawPoint( r.left()+1, r.top() + 1 );
p->drawLine( r.left()+2, r.top(),
r.right() - 2, r.top() );
p->setPen( tb->colorGroup().dark() );
p->drawPoint( r.right() - 1, r.top() + 1 );
p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
} else if ( tb->shape() == QTabBar::RoundedBelow ) {
if ( selected ) {
p->setPen( tb->colorGroup().background() );
p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
tb->palette().normal().brush( QColorGroup::Background ));
} else {
p->setPen( tb->colorGroup().dark() );
p->drawLine( r.left(), r.top(),
r.right(), r.top() );
r.setRect( r.left() + 2, r.top(),
r.width() - 4, r.height() - 2 );
p->setPen( tb->colorGroup().button() );
p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
tb->palette().normal().brush( QColorGroup::Button ));
}
p->setPen( tb->colorGroup().dark() );
p->drawLine( r.right(), r.top(),
r.right(), r.bottom() - 2 );
p->drawPoint( r.right() - 1, r.bottom() - 1 );
p->drawLine( r.right() - 2, r.bottom(),
r.left() + 2, r.bottom() );
p->setPen( tb->colorGroup().light() );
p->drawLine( r.left(), r.top()+1,
r.left(), r.bottom() - 2 );
p->drawPoint( r.left() + 1, r.bottom() - 1 );
if ( r.left() == 0 )
p->drawPoint( tb->rect().topLeft() );
} else {
QCommonStyle::drawTab( p, tb, t, selected );
}
}
static const int motifItemFrame = 0; // menu item frame width
static const int motifSepHeight = 2; // separator item height
static const int motifItemHMargin = 1; // menu item hor text margin
static const int motifItemVMargin = 2; // menu item ver text margin
static const int motifArrowHMargin = 0; // arrow horizontal margin
static const int motifTabSpacing = 12; // space between text and tab
static const int motifCheckMarkHMargin = 1; // horiz. margins of check mark
static const int windowsRightBorder = 8; // right border on windows
static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
/*! \reimp
*/
int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
{
#ifndef QT_NO_MENUDATA
int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
if ( mi->isSeparator() )
return 10; // arbitrary
else if ( mi->pixmap() )
w += mi->pixmap()->width(); // pixmap only
if ( !mi->text().isNull() ) {
if ( mi->text().find('\t') >= 0 ) // string contains tab
w += motifTabSpacing;
}
if ( maxpmw ) { // we have iconsets
w += maxpmw;
w += 6; // add a little extra border around the iconset
}
if ( checkable && maxpmw < windowsCheckMarkWidth ) {
w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
}
if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
w += motifCheckMarkHMargin; // add space to separate the columns
w += windowsRightBorder; // windows has a strange wide border on the right side
return w;
#endif
}
/*! \reimp
*/
int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
{
#ifndef QT_NO_MENUDATA
int h = 0;
if ( mi->isSeparator() ) // separator height
h = motifSepHeight;
else if ( mi->pixmap() ) // pixmap height
h = mi->pixmap()->height() + 2*motifItemFrame;
else // text height
h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
}
if ( mi->custom() )
h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
return h;
#endif
}
void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
const QPalette& pal,
bool act, bool enabled, int x, int y, int w, int h)
{
#ifndef QT_NO_MENUDATA
const QColorGroup & g = pal.active();
bool dis = !enabled;
QColorGroup itemg = dis ? pal.disabled() : pal.active();
if ( checkable )
maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
int checkcol = maxpmw;
if ( mi && mi->isSeparator() ) { // draw separator
p->setPen( g.dark() );
p->drawLine( x, y, x+w, y );
p->setPen( g.light() );
p->drawLine( x, y+1, x+w, y+1 );
return;
}
QBrush fill = act? g.brush( QColorGroup::Highlight ) :
g.brush( QColorGroup::Button );
p->fillRect( x, y, w, h, fill);
if ( !mi )
return;
if ( mi->isChecked() ) {
if ( act && !dis ) {
qDrawShadePanel( p, x, y, checkcol, h,
g, TRUE, 1, &g.brush( QColorGroup::Button ) );
} else {
qDrawShadePanel( p, x, y, checkcol, h,
g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
}
} else if ( !act ) {
p->fillRect(x, y, checkcol , h,
g.brush( QColorGroup::Button ));
}
if ( mi->iconSet() ) { // draw iconset
QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
if (act && !dis )
mode = QIconSet::Active;
QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
int pixw = pixmap.width();
int pixh = pixmap.height();
if ( act && !dis ) {
if ( !mi->isChecked() )
qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
}
QRect cr( x, y, checkcol, h );
QRect pmr( 0, 0, pixw, pixh );
pmr.moveCenter( cr.center() );
p->setPen( itemg.text() );
p->drawPixmap( pmr.topLeft(), pixmap );
QBrush fill = act? g.brush( QColorGroup::Highlight ) :
g.brush( QColorGroup::Button );
p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
} else if ( checkable ) { // just "checking"...
int mw = checkcol + motifItemFrame;
int mh = h - 2*motifItemFrame;
if ( mi->isChecked() ) {
drawCheckMark( p, x + motifItemFrame + 2,
y+motifItemFrame, mw, mh, itemg, act, dis );
}
}
p->setPen( act ? g.highlightedText() : g.buttonText() );
QColor discol;
if ( dis ) {
discol = itemg.text();
p->setPen( discol );
}
int xm = motifItemFrame + checkcol + motifItemHMargin;
if ( mi->custom() ) {
int m = motifItemVMargin;
p->save();
if ( dis && !act ) {
p->setPen( g.light() );
mi->custom()->paint( p, itemg, act, enabled,
x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
p->setPen( discol );
}
mi->custom()->paint( p, itemg, act, enabled,
x+xm, y+m, w-xm-tab+1, h-2*m );
p->restore();
}
QString s = mi->text();
if ( !s.isNull() ) { // draw text
int t = s.find( '\t' );
int m = motifItemVMargin;
const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
if ( t >= 0 ) { // draw tab text
if ( dis && !act ) {
p->setPen( g.light() );
p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
p->setPen( discol );
}
p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
}
if ( dis && !act ) {
p->setPen( g.light() );
p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
p->setPen( discol );
}
p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
} else if ( mi->pixmap() ) { // draw pixmap
QPixmap *pixmap = mi->pixmap();
if ( pixmap->depth() == 1 )
p->setBackgroundMode( OpaqueMode );
p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
if ( pixmap->depth() == 1 )
p->setBackgroundMode( TransparentMode );
}
if ( mi->popup() ) { // draw sub menu arrow
int dim = (h-2*motifItemFrame) / 2;
if ( act ) {
if ( !dis )
discol = white;
QColorGroup g2( discol, g.highlight(),
white, white,
dis ? discol : white,
discol, white );
drawArrow( p, RightArrow, FALSE,
x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
dim, dim, g2, TRUE );
} else {
drawArrow( p, RightArrow,
FALSE,
x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
dim, dim, g, mi->isEnabled() );
}
}
#endif
}
#endif
diff --git a/library/qpetoolbar.cpp b/library/qpetoolbar.cpp
index 7f95eda..bd2c9b7 100644
--- a/library/qpetoolbar.cpp
+++ b/library/qpetoolbar.cpp
@@ -1,52 +1,50 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of 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 "qpetoolbar.h"
-#include "qpemenubar.h"
-#include <qtoolbutton.h>
/*!
\class QPEToolBar qpemenubar.h
\brief The QPEToolBar class is obsolete. Use QToolBar instead.
\obsolete
The QPEToolBar class is obsolete. Use QToolBar instead.
\sa QToolBar
*/
/*!
Constructs a QPEToolBar just as you would construct
a QToolBar, passing \a parent and \a name.
*/
QPEToolBar::QPEToolBar( QMainWindow *parent, const char *name )
: QToolBar( parent, name )
{
}
/*!
\internal
*/
void QPEToolBar::childEvent( QChildEvent *e )
{
QToolBar::childEvent( e );
}
diff --git a/library/qt_override.cpp b/library/qt_override.cpp
index df5a419..4d1f475 100644
--- a/library/qt_override.cpp
+++ b/library/qt_override.cpp
@@ -1,177 +1,175 @@
#include <qpe/qpeapplication.h>
-#include <qwsdecoration_qws.h>
-#include <qcommonstyle.h>
#include <qfontdatabase.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <sys/param.h> // for toolchains with old libc headers
#include "qt_override_p.h"
#if QT_VERSION > 233
struct color_fix_t {
char *m_app;
char *m_class;
char *m_name;
QColorGroup::ColorRole m_set;
QColorGroup::ColorRole m_get;
};
#ifndef OPIE_NO_OVERRIDE_QT
static const color_fix_t apps_that_need_special_colors [] = {
{ "HancomMobileWord", "HTextEdit", 0, QColorGroup::Background, QColorGroup::Base },
{ "neocal", "Display", 0, QColorGroup::Background, QColorGroup::Base },
{ 0, 0, 0, QColorGroup::Base, QColorGroup::Base }
};
static const char * const apps_that_need_pointsizes_times_10 [] = {
"HancomMobileWord",
"hancomsheet",
"HancomPresenterViewer",
0
};
int Opie::force_appearance = 0;
// Return the *real* name of the binary - not just a quick guess
// by looking at argv [0] (which could be anything)
static void binaryNameFree ( )
{
::free ((void *) Opie::binaryName ( )); // we need to cast away the const here
}
const char *Opie::binaryName ( )
{
static const char *appname = 0;
if ( !appname ) {
char dst [PATH_MAX + 1];
int l = ::readlink ( "/proc/self/exe", dst, PATH_MAX );
if ( l <= 0 )
l = 0;
dst [l] = 0;
const char *b = ::strrchr ( dst, '/' );
appname = ::strdup ( b ? b + 1 : dst );
::atexit ( binaryNameFree );
}
return appname;
}
#else
int Opie::force_appearance = 0;
#endif
// Fix for a toolchain incompatibility (binaries compiled with
// old tcs using shared libs compiled with newer tcs)
extern "C" {
extern void __gmon_start__ ( ) __attribute__(( weak ));
extern void __gmon_start__ ( )
{
}
}
// Fix for apps, that use QPainter::eraseRect() which doesn't work with styles
// that set a background pixmap (it would be easier to fix eraseRect(), but
// TT made it an inline ...)
void QPEApplication::polish ( QWidget *w )
{
#ifndef OPIE_NO_OVERRIDE_QT
// qDebug ( "QPEApplication::polish()" );
for ( const color_fix_t *ptr = apps_that_need_special_colors; ptr-> m_app; ptr++ ) {
if (( ::strcmp ( Opie::binaryName ( ), ptr-> m_app ) == 0 ) &&
( ptr-> m_class ? w-> inherits ( ptr-> m_class ) : true ) &&
( ptr-> m_name ? ( ::strcmp ( w-> name ( ), ptr-> m_name ) == 0 ) : true )) {
QPalette pal = w-> palette ( );
pal. setColor ( ptr-> m_set, pal. color ( QPalette::Active, ptr-> m_get ));
w-> setPalette ( pal );
}
}
#endif
QApplication::polish ( w );
}
#ifndef OPIE_NO_OVERRIDE_QT
// Fix for the binary incompatibility that TT introduced in Qt/E 2.3.4 -- point sizes
// were multiplied by 10 (which was incorrect)
QValueList <int> QFontDatabase::pointSizes ( QString const &family, QString const &style, QString const &charset )
{
// qDebug ( "QFontDatabase::pointSizes()" );
QValueList <int> sl = pointSizes_NonWeak ( family, style, charset );
for ( const char * const *ptr = apps_that_need_pointsizes_times_10; *ptr; ptr++ ) {
if ( ::strcmp ( Opie::binaryName ( ), *ptr ) == 0 ) {
for ( QValueList <int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
*it *= 10;
}
}
return sl;
}
// Various style/font/color related overrides for weak symbols in Qt/E,
// which allows us to force the usage of the global Opie appearance.
void QApplication::setStyle ( QStyle *style )
{
// qDebug ( "QApplication::setStyle()" );
if ( Opie::force_appearance & Opie::Force_Style )
delete style;
else
QApplication::setStyle_NonWeak ( style );
}
void QApplication::setPalette ( const QPalette &pal, bool informWidgets, const char *className )
{
// qDebug ( "QApplication::setPalette()" );
if (!( Opie::force_appearance & Opie::Force_Style ))
QApplication::setPalette_NonWeak ( pal, informWidgets, className );
}
void QApplication::setFont ( const QFont &fnt, bool informWidgets, const char *className )
{
// qDebug ( "QApplication::setFont()" );
if (!( Opie::force_appearance & Opie::Force_Font ))
QApplication::setFont_NonWeak ( fnt, informWidgets, className );
}
void QApplication::qwsSetDecoration ( QWSDecoration *deco )
{
// qDebug ( "QApplication::qwsSetDecoration()" );
if ( Opie::force_appearance & Opie::Force_Decoration )
delete deco;
else
QApplication::qwsSetDecoration_NonWeak ( deco );
}
#endif
#endif
diff --git a/library/resource.cpp b/library/resource.cpp
index f70658d..cfa0d26 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -1,233 +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.
**
**********************************************************************/
#define QTOPIA_INTERNAL_MIMEEXT
#include <qpe/qpeapplication.h>
#include "resource.h"
#include "mimetype.h"
#include <qdir.h>
-#include <qfile.h>
-#include <qregexp.h>
#include <qpixmapcache.h>
-#include <qpainter.h>
// this namespace is just a workaround for a gcc bug
// gcc exports inline functions in the generated file
// inlinepics_p.h
namespace {
#include "inlinepics_p.h"
}
static bool g_notUseSet = ::getenv("OVERWRITE_ICON_SET");
/*!
\class Resource resource.h
\brief The Resource class provides access to named resources.
The resources may be provided from files or other sources.
The allSounds() function returns a list of all the sounds available.
A particular sound can be searched for using findSound().
Images can be loaded with loadImage(), loadPixmap(), loadBitmap()
and loadIconSet().
\ingroup qtopiaemb
*/
/*!
\fn Resource::Resource()
\internal
*/
/*!
Returns the QPixmap called \a pix. You should avoid including
any filename type extension (e.g. .png, .xpm).
*/
QPixmap Resource::loadPixmap( const QString &pix )
{
QPixmap pm;
QString key="QPE_"+pix;
if ( !QPixmapCache::find(key,pm) ) {
pm.convertFromImage(loadImage(pix));
QPixmapCache::insert(key,pm);
}
return pm;
}
/*!
Returns the QBitmap called \a pix. You should avoid including
any filename type extension (e.g. .png, .xpm).
*/
QBitmap Resource::loadBitmap( const QString &pix )
{
QBitmap bm;
bm = loadPixmap(pix);
return bm;
}
/*!
Returns the filename of a pixmap called \a pix. You should avoid including
any filename type extension (e.g. .png, .xpm).
Normally you will use loadPixmap() rather than this function.
*/
QString Resource::findPixmap( const QString &pix )
{
QString picsPath = QPEApplication::qpeDir() + "pics/";
QString f;
// Common case optimizations...
f = picsPath + pix + ".png";
if ( QFile( f ).exists() )
return f;
f = picsPath + pix + ".xpm";
if ( QFile( f ).exists() )
return f;
// All formats...
QStrList fileFormats = QImageIO::inputFormats();
QString ff = fileFormats.first();
while ( fileFormats.current() ) {
QStringList exts = MimeType("image/"+ff.lower()).extensions();
for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
QString f = picsPath + pix + "." + *it;
if ( QFile(f).exists() )
return f;
}
ff = fileFormats.next();
}
// Finally, no (or existing) extension...
if ( QFile( picsPath + pix ).exists() )
return picsPath + pix;
//qDebug("Cannot find pixmap: %s", pix.latin1());
return QString();
}
/*!
Returns a sound file for a sound called \a name.
You should avoid including any filename type extension (e.g. .wav),
as the system will search for only those fileformats which are supported
by the library.
Currently, only WAV files are supported.
*/
QString Resource::findSound( const QString &name )
{
QString picsPath = QPEApplication::qpeDir() + "sounds/";
QString result;
if ( QFile( (result = picsPath + name + ".wav") ).exists() )
return result;
return QString();
}
/*!
Returns a list of all sound names.
*/
QStringList Resource::allSounds()
{
QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
QStringList entries = resourcedir.entryList();
QStringList result;
for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
result.append((*i).replace(QRegExp("\\.wav"),""));
return result;
}
static QImage load_image(const QString &name)
{
if (g_notUseSet ) {
// try file
QImage img;
QString f = Resource::findPixmap(name);
if ( !f.isEmpty() )
img.load(f);
if (img.isNull() )
img = qembed_findImage(name.latin1() );
return img;
}
else{
QImage img = qembed_findImage(name.latin1());
if ( img.isNull() ) {
// No inlined image, try file
QString f = Resource::findPixmap(name);
if ( !f.isEmpty() )
img.load(f);
}
return img;
}
}
/*!
Returns the QImage called \a name. You should avoid including
any filename type extension (e.g. .png, .xpm).
*/
QImage Resource::loadImage( const QString &name)
{
#ifndef QT_NO_DEPTH_32 // have alpha-blended pixmaps
static QImage last_enabled;
static QString last_enabled_name;
if ( name == last_enabled_name )
return last_enabled;
#endif
QImage img = load_image(name);
#ifndef QT_NO_DEPTH_32 // have alpha-blended pixmaps
if ( img.isNull() ) {
// No file, try generating
if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
last_enabled_name = name.left(name.length()-9);
last_enabled = load_image(last_enabled_name);
if ( last_enabled.isNull() ) {
last_enabled_name = QString::null;
} else {
img.detach();
img.create( last_enabled.width(), last_enabled.height(), 32 );
for ( int y = 0; y < img.height(); y++ ) {
for ( int x = 0; x < img.width(); x++ ) {
QRgb p = last_enabled.pixel( x, y );
int a = qAlpha(p)/3;
int g = qGray(qRed(p),qGreen(p),qBlue(p));
img.setPixel( x, y, qRgba(g,g,g,a) );
}
}
img.setAlphaBuffer( TRUE );
}
}
}
#endif
return img;
}
/*!
\fn QIconSet Resource::loadIconSet( const QString &name )
Returns a QIconSet for the pixmap named \a name. A disabled icon is
generated that conforms to the Qtopia look & feel. You should avoid
including any filename type extension (eg. .png, .xpm).
*/
diff --git a/library/sound.cpp b/library/sound.cpp
index 5b67995..ee2aabc 100644
--- a/library/sound.cpp
+++ b/library/sound.cpp
@@ -1,224 +1,222 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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/resource.h>
#include <qpe/sound.h>
#include <qpe/qcopenvelope_qws.h>
#include <qsound.h>
#include <qfile.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#ifndef QT_NO_SOUND
#include <sys/soundcard.h>
#endif
-#include "config.h"
-#include <qmessagebox.h>
#ifndef QT_NO_SOUND
static int WAVsoundDuration(const QString& filename)
{
// bad solution
// most of this is copied from qsoundqss.cpp
QFile input(filename);
if ( !input.open(IO_ReadOnly) )
return 0;
struct QRiffChunk {
char id[4];
Q_UINT32 size;
char data[4/*size*/];
} chunk;
struct {
Q_INT16 formatTag;
Q_INT16 channels;
Q_INT32 samplesPerSec;
Q_INT32 avgBytesPerSec;
Q_INT16 blockAlign;
Q_INT16 wBitsPerSample;
} chunkdata;
int total = 0;
while(1) {
// Keep reading chunks...
const int n = sizeof(chunk)-sizeof(chunk.data);
if ( input.readBlock((char*)&chunk,n) != n )
break;
if ( qstrncmp(chunk.id,"data",4) == 0 ) {
total += chunkdata.avgBytesPerSec ?
chunk.size * 1000 / chunkdata.avgBytesPerSec : 0;
//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0);
input.at(input.at()+chunk.size-4);
} else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
char d[4];
if ( input.readBlock(d,4) != 4 )
return 0;
if ( qstrncmp(d,"WAVE",4) != 0 ) {
// skip
//qDebug("skip %.4s RIFF chunk",d);
if ( chunk.size < 10000000 )
(void)input.at(input.at()+chunk.size-4);
}
} else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) {
if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) )
return 0;
#define WAVE_FORMAT_PCM 1
if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) {
//qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag);
return 0;
}
} else {
//qDebug("skip %.4s chunk",chunk.id);
// ignored chunk
if ( chunk.size < 10000000 )
(void)input.at(input.at()+chunk.size);
}
}
//qDebug("%dms",total);
return total;
}
class SoundData : public QSound {
public:
SoundData ( const QString& name ) :
QSound ( Resource::findSound ( name )),
filename ( Resource::findSound ( name ))
{
loopsleft=0;
ms = WAVsoundDuration(filename);
}
void playLoop ( int loopcnt = -1 )
{
// needs server support
loopsleft = loopcnt;
if ( ms )
startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency
play ( );
}
void timerEvent ( QTimerEvent *e )
{
if ( loopsleft >= 0 ) {
if ( --loopsleft <= 0 ) {
killTimer ( e-> timerId ( ));
loopsleft = 0;
return;
}
}
play();
}
bool isFinished ( ) const
{
return ( loopsleft == 0 );
}
private:
QString filename;
int loopsleft;
int ms;
};
#endif
/*! Opens a wave sound file \a name for playing
* Resource is used for finding the file
**/
Sound::Sound(const QString& name)
{
#ifndef QT_NO_SOUND
d = new SoundData(name);
#endif
}
/*! Destroys the sound */
Sound::~Sound()
{
#ifndef QT_NO_SOUND
delete d;
#endif
}
/*! Play the sound once */
void Sound::play()
{
#ifndef QT_NO_SOUND
d->playLoop(1);
#endif
}
/*! Play the sound, repeatedly until stop() is called */
void Sound::playLoop()
{
#ifndef QT_NO_SOUND
d->killTimers();
d->playLoop();
#endif
}
/*! Do not repeat the sound after it finishes. This will end a playLoop() */
void Sound::stop()
{
#ifndef QT_NO_SOUND
d->killTimers();
#endif
}
bool Sound::isFinished() const
{
#ifndef QT_NO_SOUND
return d->isFinished();
#else
return true;
#endif
}
/*! Sounds the audible system alarm. This is used for applications such
as Calendar when it needs to alarm the user of an event.
*/
void Sound::soundAlarm()
{
#ifndef QT_NO_COP
QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
#endif
}
/*! \class Sound
\brief The Sound class plays WAVE sound files and can invoke the audible alarm.
The Sound class is constructed with the .wav music file name. The Sound
class retrieves the sound file from the shared Resource class. This class
ties together QSound and the available sound resources.
To sound an audible system alarm, call the static method soundAlarm()
\ingroup qtopiaemb
*/
diff --git a/library/storage.cpp b/library/storage.cpp
index d98139b..0ea465b 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,405 +1,401 @@
/**********************************************************************
** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Opie 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/storage.h>
-#include <qpe/custom.h>
-#include <qfile.h>
-#include <qtimer.h>
#include <qcopchannel_qws.h>
#include <stdio.h>
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
#include <sys/vfs.h>
#include <mntent.h>
#endif
#ifdef Q_OS_MACX
# include <sys/param.h>
# include <sys/ucred.h>
# include <sys/mount.h>
# include <stdio.h> // For strerror()
# include <errno.h>
#endif /* Q_OS_MACX */
-#include <qstringlist.h>
// Shouldn't be here ! (eilers)
// #include <sys/vfs.h>
// #include <mntent.h>
static bool isCF(const QString& m)
{
#ifndef Q_OS_MACX
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];
char devname[80];
while ( fgets( line, 1024, f ) )
{
// 0 ide ide-cs 0 hda 3 0
if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
{
if ( QString(devtype) == "ide" && m.find(devname)>0 )
{
fclose(f);
return TRUE;
}
}
}
fclose(f);
}
#endif /* Q_OS_MACX */
return FALSE;
}
/*! \class StorageInfo storage.h
\brief The StorageInfo class describes the disks mounted on the file system.
This class provides access to the mount information for the Linux
filesystem. Each mount point is represented by the FileSystem class.
To ensure this class has the most up to date size information, call
the update() method. Note that this will automatically be signaled
by the operating system when a disk has been mounted or unmounted.
\ingroup qtopiaemb
*/
/*! Constructor that determines the current mount points of the filesystem.
The standard \a parent parameters is passed on to QObject.
*/
StorageInfo::StorageInfo( QObject *parent )
: QObject( parent )
{
mFileSystems.setAutoDelete( TRUE );
channel = new QCopChannel( "QPE/Card", this );
connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
update();
}
/*! Returns the longest matching FileSystem that starts with the
same prefix as \a filename as its mount point.
*/
const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
{
for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
{
if ( filename.startsWith( (*i)->path() ) )
return (*i);
}
return 0;
}
void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
{
if ( msg == "mtabChanged()" )
update();
}
/*! Updates the mount and free space available information for each mount
point. This method is automatically called when a disk is mounted or
unmounted.
*/
// cause of the lack of a d pointer we need
// to store informations in a config file :(
void StorageInfo::update()
{
//qDebug("StorageInfo::updating");
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
struct mntent *me;
FILE *mntfp = setmntent( "/etc/mtab", "r" );
QStringList curdisks;
QStringList curopts;
QStringList curfs;
bool rebuild = FALSE;
int n=0;
if ( mntfp )
{
while ( (me = getmntent( mntfp )) != 0 )
{
QString fs = me->mnt_fsname;
if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
|| fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
|| fs.left( 14 ) == "/dev/mmc/part1"
|| fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
{
n++;
curdisks.append(fs);
curopts.append( me->mnt_opts );
//qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
curfs.append( me->mnt_dir );
bool found = FALSE;
for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
{
if ( (*i)->disk() == fs )
{
found = TRUE;
break;
}
}
if ( !found )
rebuild = TRUE;
}
}
endmntent( mntfp );
}
if ( rebuild || n != (int)mFileSystems.count() )
{
mFileSystems.clear();
QStringList::ConstIterator it=curdisks.begin();
QStringList::ConstIterator fsit=curfs.begin();
QStringList::ConstIterator optsIt=curopts.begin();
for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt)
{
QString opts = *optsIt;
QString disk = *it;
QString humanname;
bool removable = FALSE;
if ( isCF(disk) )
{
humanname = tr("CF Card");
removable = TRUE;
}
else if ( disk == "/dev/hda1" )
{
humanname = tr("Hard Disk");
}
else if ( disk.left(9) == "/dev/mmcd" )
{
humanname = tr("SD Card");
removable = TRUE;
}
else if ( disk.left( 14 ) == "/dev/mmc/part1" )
{
humanname = tr("MMC Card");
removable = TRUE;
}
else if ( disk.left(7) == "/dev/hd" )
humanname = tr("Hard Disk") + " " + disk;
else if ( disk.left(7) == "/dev/sd" )
humanname = tr("SCSI Hard Disk") + " " + disk;
else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
humanname = tr("Internal Memory");
else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
humanname = tr("Internal Storage");
else if ( disk.left(14) == "/dev/mtdblock/" )
humanname = tr("Internal Storage") + " " + disk;
else if ( disk.left(13) == "/dev/mtdblock" )
humanname = tr("Internal Storage") + " " + disk;
else if ( disk.left(9) == "/dev/root" )
humanname = tr("Internal Storage") + " " + disk;
else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
humanname = tr("Internal Memory");
FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
mFileSystems.append( fs );
}
emit disksChanged();
}
else
{
// just update them
for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
i.current()->update();
}
#endif
}
bool deviceTab( const char *device)
{
QString name = device;
bool hasDevice=false;
#ifdef Q_OS_MACX
// Darwin (MacOS X)
struct statfs** mntbufp;
int count = 0;
if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 )
{
qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) );
hasDevice = false;
}
for( int i = 0; i < count; i++ )
{
QString deviceName = mntbufp[i]->f_mntfromname;
qDebug(deviceName);
if( deviceName.left( name.length() ) == name )
hasDevice = true;
}
#else
// Linux
struct mntent *me;
FILE *mntfp = setmntent( "/etc/mtab", "r" );
if ( mntfp )
{
while ( (me = getmntent( mntfp )) != 0 )
{
QString deviceName = me->mnt_fsname;
// qDebug(deviceName);
if( deviceName.left(name.length()) == name)
{
hasDevice = true;
}
}
}
endmntent( mntfp );
#endif /* Q_OS_MACX */
return hasDevice;
}
/*!
* @fn static bool StorageInfo::hasCf()
* @brief returns whether device has Cf mounted
*
*/
bool StorageInfo::hasCf()
{
return deviceTab("/dev/hd");
}
/*!
* @fn static bool StorageInfo::hasSd()
* @brief returns whether device has SD mounted
*
*/
bool StorageInfo::hasSd()
{
return deviceTab("/dev/mmcd");
}
/*!
* @fn static bool StorageInfo::hasMmc()
* @brief returns whether device has mmc mounted
*
*/
bool StorageInfo::hasMmc()
{
bool hasMmc=false;
if( deviceTab("/dev/mmc/part"))
hasMmc=true;
if( deviceTab("/dev/mmcd"))
hasMmc=true;
return hasMmc;
}
/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const
Returns a list of all available mounted file systems.
\warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp)
*/
/*! \fn void StorageInfo::disksChanged()
Gets emitted when a disk has been mounted or unmounted, such as when
a CF c
*/
//---------------------------------------------------------------------------
FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
: fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
{
update();
}
void FileSystem::update()
{
#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
struct statfs fs;
if ( !statfs( fspath.latin1(), &fs ) )
{
blkSize = fs.f_bsize;
totalBlks = fs.f_blocks;
availBlks = fs.f_bavail;
}
else
{
blkSize = 0;
totalBlks = 0;
availBlks = 0;
}
#endif
}
/*! \class FileSystem storage.h
\brief The FileSystem class describes a single mount point.
This class simply returns information about a mount point, including
file system name, mount point, human readable name, size information
and mount options information.
\ingroup qtopiaemb
\sa StorageInfo
*/
/*! \fn const QString &FileSystem::disk() const
Returns the file system name, such as /dev/hda3
*/
/*! \fn const QString &FileSystem::path() const
Returns the mount path, such as /home
*/
/*! \fn const QString &FileSystem::name() const
Returns the translated, human readable name for the mount directory.
*/
/*! \fn const QString &FileSystem::options() const
Returns the mount options
*/
/*! \fn long FileSystem::blockSize() const
Returns the size of each block on the file system.
*/
/*! \fn long FileSystem::totalBlocks() const
Returns the total number of blocks on the file system
*/
/*! \fn long FileSystem::availBlocks() const
Returns the number of available blocks on the file system
*/
/*! \fn bool FileSystem::isRemovable() const
Returns flag whether the file system can be removed, such as a CF card
would be removable, but the internal memory wouldn't
*/
/*! \fn bool FileSystem::isWritable() const
Returns flag whether the file system is mounted as writable or read-only.
Returns FALSE if read-only, TRUE if read and write.
*/
/*! \fn QStringList StorageInfo::fileSystemNames() const
Returns a list of filesystem names.
*/
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index 4343eab..f28100b 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,303 +1,302 @@
/**********************************************************************
** 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>
#include <qcopchannel_qws.h>
#include <qpe/qpeapplication.h>
#include <qmessagebox.h>
/*!
\class TimeZoneSelector
\brief The TimeZoneSelector widget allows users to configure their time zone information.
\ingroup qtopiaemb
*/
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(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
}
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();
}
}
/*!
Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be
populated with the available timezones.
*/
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() ) );
}
/*!
Destroys a TimeZoneSelector.
*/
TimeZoneSelector::~TimeZoneSelector()
{
}
void TimeZoneSelector::setLocalIncluded(bool b)
{
d->includeLocal = b;
cmbTz->updateZones();
}
bool TimeZoneSelector::localIncluded() const
{
return d->includeLocal;
}
/*!
Returns the currently selected timezone as a string in location format, e.g.
\code Australia/Brisbane \endcode
*/
QString TimeZoneSelector::currentZone() const
{
return cmbTz->currZone();
}
/*!
Sets the current timezone to \a id.
*/
void TimeZoneSelector::setCurrentZone( const QString& id )
{
cmbTz->setCurrZone( id );
}
/*! \fn void TimeZoneSelector::signalNewTz( const QString& id )
This signal is emitted when a timezone has been selected by the user. The id
is a \l QString in location format, eg \code Australia/Brisbane \endcode
*/
void TimeZoneSelector::slotTzActive( int )
{
emit signalNewTz( cmbTz->currZone() );
}
void TimeZoneSelector::slotExecute( void )
{
// execute the world time application...
if (QFile::exists(QPEApplication::qpeDir()+"bin/citytime"))
Global::execute( "citytime" );
else
QMessageBox::warning(this,tr("citytime executable not found"),
tr("In order to choose the time zones,\nplease install 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;
}