summaryrefslogtreecommitdiff
path: root/library
Side-by-side diff
Diffstat (limited to 'library') (more/less context) (ignore 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,413 +1,408 @@
/**********************************************************************
** 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 ;
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 8763eb2..9c60f1a 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,425 +1,421 @@
/**********************************************************************
** 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;
}
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,407 +1,405 @@
/**********************************************************************
** 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.
*/
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index 188d8e1..e4ec2bf 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -1,417 +1,412 @@
/**********************************************************************
** 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();
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 728045f..76e022f 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,417 +1,412 @@
/**********************************************************************
** 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 )
{
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index 408be20..1e7384e 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -1,411 +1,408 @@
/**********************************************************************
** 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();
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 4039243..7c29aba 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,419 +1,417 @@
/**********************************************************************
** 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();
}
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,435 +1,433 @@
/**********************************************************************
** 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.
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,407 +1,405 @@
/**********************************************************************
** 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.
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c7ef2b7..262221e 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -721,769 +721,768 @@ QPEApplication::QPEApplication( int & argc, char **argv, Type t )
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
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,409 +1,406 @@
/**********************************************************************
** 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 );
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;
}