summaryrefslogtreecommitdiff
path: root/library
authorllornkcor <llornkcor>2006-07-09 18:56:40 (UTC)
committer llornkcor <llornkcor>2006-07-09 18:56:40 (UTC)
commit36dece4760b1ac1799929221b49eb3bee98c2367 (patch) (side-by-side diff)
treea45f66d2d90bd9fbbff8e8903cd1cb9323c39f6e /library
parent604065c6e662cb3894acf03abadafacc3ab52913 (diff)
downloadopie-36dece4760b1ac1799929221b49eb3bee98c2367.zip
opie-36dece4760b1ac1799929221b49eb3bee98c2367.tar.gz
opie-36dece4760b1ac1799929221b49eb3bee98c2367.tar.bz2
initial commit to add video4linux camera app from qtopia 2, needs more work
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/categories.h1
-rw-r--r--library/global.cpp49
-rw-r--r--library/global.h6
-rw-r--r--library/library.pro2
-rw-r--r--library/locationcombo.cpp295
-rw-r--r--library/locationcombo.h88
-rw-r--r--library/qlibrary_unix.cpp4
-rw-r--r--library/timestring.cpp255
-rw-r--r--library/timestring.h94
9 files changed, 683 insertions, 111 deletions
diff --git a/library/backend/categories.h b/library/backend/categories.h
index 91c93e7..6be3bc0 100644
--- a/library/backend/categories.h
+++ b/library/backend/categories.h
@@ -31,6 +31,7 @@
#include "palmtopuidgen.h"
class CategoryGroup;
+QString categoryFileName();
#if defined(QPC_TEMPLATEDLL)
// MOC_SKIP_BEGIN
diff --git a/library/global.cpp b/library/global.cpp
index ec87555..f7a0767 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -808,5 +808,54 @@ QStringList Global::helpPath()
return path;
}
+/*!
+ \internal
+ Truncate file to size specified
+ \a f must be an open file
+ \a size must be a positive value
+ */
+bool Global::truncateFile(QFile &f, int size){
+ if (!f.isOpen())
+ return FALSE;
+
+ return ::ftruncate(f.handle(), size) != -1;
+}
+
+
+
+
+// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS)
+// extern int qws_display_id;
+// #endif
+
+/*!
+ /internal
+ Returns the default system path for storing temporary files.
+ Note: This does not it ensure that the provided directory exists
+*/
+QString Global::tempDir()
+{
+ QString result;
+#ifdef Q_OS_UNIX
+#ifdef Q_WS_QWS
+ result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id));
+#else
+ result="/tmp/";
+#endif
+#else
+ if (getenv("TEMP"))
+ result = getenv("TEMP");
+ else
+ result = getenv("TMP");
+
+ if (result[(int)result.length() - 1] != QDir::separator())
+ result.append(QDir::separator());
+#endif
+
+ return result;
+}
+
+//#endif
+
#include "global.moc"
diff --git a/library/global.h b/library/global.h
index 1136b12..f32c498 100644
--- a/library/global.h
+++ b/library/global.h
@@ -27,7 +27,7 @@ class QLabel;
class QWidget;
class AppLnk;
class DocLnkSet;
-
+class QFile;
class Global
{
public:
@@ -80,6 +80,10 @@ public:
static QStringList languageList();
static QStringList helpPath();
#endif
+//#ifdef QTOPIA_INTERNAL_FILEOPERATIONS
+ static bool truncateFile(QFile &f, int size);
+ static QString tempDir( );
+//#endif
private:
static void invoke( const QString &exec);
diff --git a/library/library.pro b/library/library.pro
index 7143454..4142529 100644
--- a/library/library.pro
+++ b/library/library.pro
@@ -59,6 +59,7 @@ HEADERS = calendar.h \
windowdecorationinterface.h \
textcodecinterface.h \
imagecodecinterface.h \
+ locationcombo.h \
qpeglobal.h
SOURCES = calendar.cpp \
@@ -116,6 +117,7 @@ SOURCES = calendar.cpp \
findwidget_p.cpp \
finddialog.cpp \
lnkproperties.cpp \
+ locationcombo.cpp \
widget_showing.cpp
diff --git a/library/locationcombo.cpp b/library/locationcombo.cpp
new file mode 100644
index 0000000..31429f5
--- a/dev/null
+++ b/library/locationcombo.cpp
@@ -0,0 +1,295 @@
+/**********************************************************************
+** Copyright (C) 2000-2006 Trolltech AS. All rights reserved.
+**
+** This file is part of the Qtopia Environment.
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
+**
+** A copy of the GNU GPL license version 2 is included in this package as
+** LICENSE.GPL.
+**
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+** See the GNU General Public License for more details.
+**
+** In addition, as a special exception Trolltech gives permission to link
+** the code of this program with Qtopia applications copyrighted, developed
+** and distributed by Trolltech under the terms of the Qtopia Personal Use
+** License Agreement. You must comply with the GNU General Public License
+** in all respects for all of the code used other than the applications
+** licensed under the Qtopia Personal Use License Agreement. If you modify
+** this file, you may extend this exception to your version of the file,
+** but you are not obligated to do so. If you do not wish to do so, delete
+** this exception statement from your version.
+**
+** 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 "locationcombo.h"
+
+#include <qpe/ir.h>
+#include <qpe/applnk.h>
+#include <qpe/global.h>
+#include <qpe/categorywidget.h>
+#include <qpe/categoryselect.h>
+#ifdef QWS
+#include <qpe/qcopenvelope_qws.h>
+#endif
+#include <qpe/filemanager.h>
+#include <qpe/config.h>
+#include <qpe/storage.h>
+#include <qpe/global.h>
+#include <qtopia/qpemessagebox.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 <qdir.h>
+#include <qfileinfo.h>
+#include <qmessagebox.h>
+#include <qsize.h>
+#include <qcombobox.h>
+#include <qregexp.h>
+
+#include <qradiobutton.h>
+#include <qlayout.h>
+
+#include <stdlib.h>
+
+/*!
+ \class LocationCombo locationcombo.h
+ \brief The LocationCombo class displays a list of available storage
+ locations.
+
+ First availability: Qtopia 1.6
+
+ \ingroup qtopiaemb
+ \sa DocPropertiesDialog
+ */
+
+
+class LocationComboPrivate
+{
+public:
+ LocationComboPrivate() : homeLocation(-1), fileSize(0), listEmpty(TRUE) {}
+ QString originalPath;
+ int homeLocation;
+ int fileSize;
+ bool listEmpty;
+};
+
+/*!
+ Constructs a LocationCombo with parent \a parent and name \a name.
+ */
+LocationCombo::LocationCombo( QWidget *parent, const char *name )
+ : QComboBox( FALSE, parent, name )
+{
+ storage = new StorageInfo;
+ d = new LocationComboPrivate;
+ setLocation( 0 );
+ connect( this, SIGNAL(activated(int)), this, SIGNAL(newPath()) );
+ connect( storage, SIGNAL(disksChanged()), this, SLOT(updatePaths()) );
+}
+
+/*!
+ Constructs a LocationCombo with parent \a parent and name \a name.
+ \a lnk is pointer to an existing AppLnk.
+ */
+LocationCombo::LocationCombo( const AppLnk * lnk, QWidget *parent, const char *name )
+ : QComboBox( FALSE, parent, name )
+{
+ storage = new StorageInfo;
+ d = new LocationComboPrivate;
+ setLocation(lnk);
+ connect( this, SIGNAL(activated(int)), this, SIGNAL(newPath()) );
+ connect( storage, SIGNAL(disksChanged()), this, SLOT(updatePaths()) );
+}
+
+/*!
+ Destroys the widget.
+ */
+LocationCombo::~LocationCombo()
+{
+ delete storage;
+ delete d;
+}
+
+/*!
+ Sets the display of the LocationCombo to the location associated with the
+ AppLnk \a lnk.
+ */
+void LocationCombo::setLocation( const AppLnk * lnk )
+{
+ // NB: setLocation(const QString) assumes only lnk->file() is used.
+
+ if ( lnk ) {
+ QFileInfo fi( lnk->file() );
+ d->fileSize = fi.size();
+ const FileSystem *fs = storage->fileSystemOf( lnk->file() );
+ d->originalPath = fs ? fs->path() : QString::null;
+ } else {
+ d->fileSize = 0;
+ d->originalPath = QString::null;
+ }
+
+ setupCombo();
+
+ int currentLocation = -1;
+ if ( lnk ) {
+ int n = locations.count();
+ for ( int i = 0; i < n; i++ ) {
+ if ( lnk->file().contains( locations[i] ) )
+ currentLocation = i;
+ }
+ }
+ if ( currentLocation == -1 )
+ currentLocation = 0; //default to the first one
+
+ setCurrentItem( currentLocation );
+}
+
+/*!
+ \internal
+*/
+void LocationCombo::setupCombo()
+{
+ clear();
+ locations.clear();
+
+ const QList<FileSystem> &fs = storage->fileSystems();
+ QListIterator<FileSystem> it ( fs );
+ QString s;
+ QString homeDir = QDir::homeDirPath();
+ QString homeFs;
+ QString homeFsPath;
+ int index = 0;
+ for ( ; it.current(); ++it ) {
+ // we add 10k to the file size so we are sure we can also save the desktop file
+ if ( !d->fileSize || (*it)->path() == d->originalPath ||
+ (ulong)(*it)->availBlocks() * (ulong)(*it)->blockSize()
+ > (ulong)d->fileSize + 10000 )
+ {
+ if ( (*it)->isRemovable() ) {
+ insertItem( (*it)->name(), index );
+ locations.append( (*it)->path() );
+ index++;
+ } else if ( homeDir.contains( (*it)->path() ) &&
+ (*it)->path().length() > homeFsPath.length() ) {
+ homeFs = (*it)->name();
+ homeFsPath = (*it)->path();
+ }
+ }
+ }
+
+ // $HOME is *somewhere*, but not shown in Storage::fileSystems(),
+ // eg. because it's mounted in some unexpected way.
+ if ( homeFsPath.isEmpty() ) {
+ homeFs = StorageInfo::tr("Internal Storage");
+ homeFsPath = homeDir;
+ }
+
+ if ( !homeFsPath.isEmpty() ) {
+ d->homeLocation = 0;
+ insertItem( homeFs, d->homeLocation );
+ locations.prepend( homeDir );
+ } else {
+ d->homeLocation = -1;
+ }
+
+ d->listEmpty = locations.count() == 0;
+ if ( d->listEmpty ) {
+ insertItem( tr("No FileSystems Available!"), 0 );
+ locations.append( "" );
+ }
+}
+
+/*!
+ \internal
+ */
+void LocationCombo::updatePaths()
+{
+ QString oldPath = locations[currentItem()];
+
+ setupCombo();
+
+ int currentLocation = 0;
+ int n = locations.count();
+ for ( int i = 0; i < n; i++ ) {
+ if ( oldPath == locations[i] ) {
+ currentLocation = i;
+ }
+ }
+ setCurrentItem( currentLocation );
+ if ( locations[currentItem()] != oldPath )
+ emit newPath();
+}
+
+/*!
+ Returns TRUE to indicate that the user has changed the location displayed
+ by the LocationCombo. Most useful when the LocationCombo is part of a
+ dialog; when the dialog is accept()ed, LocationCombo::isChanged() can be
+ examined to check for a change of location.
+ */
+bool LocationCombo::isChanged() const
+{
+ if ( const FileSystem *fs = storage->fileSystemOf(locations[currentItem()]) )
+ return fs->path() != d->originalPath;
+
+ return TRUE;
+}
+
+/*!
+ Returns the default (home) location for the file associated with this
+ LocationCombo.
+ */
+QString LocationCombo::installationPath() const
+{
+ return currentItem() == d->homeLocation ?
+ QString("/") : locations[ currentItem() ]+"/";
+}
+
+/*!
+ Returns the document path associated with this LocationCombo. This
+ will be "\<path\>/Documents".
+ */
+QString LocationCombo::documentPath() const
+{
+ return locations[ currentItem() ]+"/Documents/";
+}
+
+/*!
+ Returns a pointer to FileSystem object, associated with the current
+ selection of the LocationCombo.
+ */
+const FileSystem *LocationCombo::fileSystem() const
+{
+ if ( d->listEmpty )
+ return 0;
+ return storage->fileSystemOf( locations[ currentItem() ] );
+}
+
+/*!
+ \fn LocationCombo::newPath()
+ Emitted when the LocationCombo changes to a new location.
+ */
+
+
+#if 0
+void LocationCombo::apply()
+{
+}
+#endif
+
diff --git a/library/locationcombo.h b/library/locationcombo.h
new file mode 100644
index 0000000..fab3dfc
--- a/dev/null
+++ b/library/locationcombo.h
@@ -0,0 +1,88 @@
+/**********************************************************************
+** Copyright (C) 2000-2006 Trolltech AS. All rights reserved.
+**
+** This file is part of the Qtopia Environment.
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
+**
+** A copy of the GNU GPL license version 2 is included in this package as
+** LICENSE.GPL.
+**
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+** See the GNU General Public License for more details.
+**
+** In addition, as a special exception Trolltech gives permission to link
+** the code of this program with Qtopia applications copyrighted, developed
+** and distributed by Trolltech under the terms of the Qtopia Personal Use
+** License Agreement. You must comply with the GNU General Public License
+** in all respects for all of the code used other than the applications
+** licensed under the Qtopia Personal Use License Agreement. If you modify
+** this file, you may extend this exception to your version of the file,
+** but you are not obligated to do so. If you do not wish to do so, delete
+** this exception statement from your version.
+**
+** 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 LOCATIONCOMBO_H
+#define LOCATIONCOMBO_H
+
+#include <qpe/qpeglobal.h>
+
+#ifdef Q_WS_QWS
+
+#include <qstringlist.h>
+#include <qcombobox.h>
+
+class AppLnk;
+class QListViewItem;
+class DocLnk;
+class FileSystem;
+class StorageInfo;
+
+
+class LocationComboPrivate;
+
+class LocationCombo : public QComboBox
+{
+ Q_OBJECT
+public:
+ LocationCombo( QWidget *parent, const char *name=0 );
+ LocationCombo( const AppLnk * lnk, QWidget *parent, const char *name=0 );
+
+ ~LocationCombo();
+
+ void setLocation( const QString& path ); // qtopia 2
+ void setLocation( const AppLnk * );
+
+ QString installationPath() const;
+ QString documentPath() const;
+ const FileSystem *fileSystem() const;
+
+ bool isChanged() const;
+
+signals:
+ void newPath();
+
+private slots:
+ void updatePaths();
+
+private:
+ void setupCombo();
+ QStringList locations;
+ StorageInfo *storage;
+ LocationComboPrivate *d;
+};
+
+
+#endif // QWS
+#endif // LNKPROPERTIES_H
diff --git a/library/qlibrary_unix.cpp b/library/qlibrary_unix.cpp
index fee73c2..f4d60cb 100644
--- a/library/qlibrary_unix.cpp
+++ b/library/qlibrary_unix.cpp
@@ -198,7 +198,7 @@ bool QLibraryPrivate::loadLibrary()
QString filename = library->library();
- pHnd = dlopen( filename.latin1() , RTLD_LAZY );
+ pHnd = ::dlopen( filename.latin1() , RTLD_LAZY );
// #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
if ( !pHnd )
qWarning( "%s", dlerror() );
@@ -211,7 +211,7 @@ bool QLibraryPrivate::freeLibrary()
if ( !pHnd )
return TRUE;
- int ec = dlclose( pHnd );
+ int ec = ::dlclose( pHnd );
if ( !ec )
pHnd = 0;
#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
diff --git a/library/timestring.cpp b/library/timestring.cpp
index 91c29ae..afd162d 100644
--- a/library/timestring.cpp
+++ b/library/timestring.cpp
@@ -1,15 +1,30 @@
/**********************************************************************
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2006 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 program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+** A copy of the GNU GPL license version 2 is included in this package as
+** LICENSE.GPL.
+**
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+** See the GNU General Public License for more details.
+**
+** In addition, as a special exception Trolltech gives permission to link
+** the code of this program with Qtopia applications copyrighted, developed
+** and distributed by Trolltech under the terms of the Qtopia Personal Use
+** License Agreement. You must comply with the GNU General Public License
+** in all respects for all of the code used other than the applications
+** licensed under the Qtopia Personal Use License Agreement. If you modify
+** this file, you may extend this exception to your version of the file,
+** but you are not obligated to do so. If you do not wish to do so, delete
+** this exception statement from your version.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
@@ -20,18 +35,21 @@
#include "timestring.h"
#include <qobject.h>
-#include <qpe/qpeapplication.h> //for qApp
+#include <qdatetime.h>
+#include <qapplication.h>
#include "config.h"
+#include <time.h>
+
-class TimeStringFormatKeeper : public QObject
+class TimeStringFormat : public QObject
{
Q_OBJECT
public:
static DateFormat currentFormat()
{
if ( !self )
- self = new TimeStringFormatKeeper;
+ self = new TimeStringFormat;
return self->format;
}
private slots:
@@ -40,24 +58,24 @@ private slots:
format = f;
}
private:
- static TimeStringFormatKeeper *self;
+ static TimeStringFormat *self;
DateFormat format;
- TimeStringFormatKeeper()
+ TimeStringFormat()
: QObject( qApp )
{
Config config("qpe");
config.setGroup( "Date" );
- format = DateFormat(QChar(config.readEntry("Separator", "/")[0]),
- (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
- (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
+ format = ::DateFormat(QChar(config.readEntry("Separator", "/")[0]),
+ (::DateFormat::Order)config.readNumEntry("ShortOrder", ::DateFormat::DayMonthYear),
+ (::DateFormat::Order)config.readNumEntry("LongOrder", ::DateFormat::DayMonthYear));
connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ),
this, SLOT( formatChanged(DateFormat) ) );
}
};
-TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0;
+TimeStringFormat *TimeStringFormat::self = 0;
QString DateFormat::toNumberString() const
{
@@ -67,13 +85,13 @@ QString DateFormat::toNumberString() const
// switch on the relavent 3 bits.
switch((_shortOrder >> (i * 3)) & 0x0007) {
case 0x0001:
- buf += QObject::tr( "D" , "Shortcut for Day");
+ buf += TimeStringFormat::tr( "D", "first letter of the word 'Day'" );
break;
case 0x0002:
- buf += QObject::tr( "M", "Shortcur for Month" );
+ buf += TimeStringFormat::tr( "M" , "first letter of the word 'Month'" );
break;
case 0x0004:
- buf += QObject::tr( "Y" );
+ buf += TimeStringFormat::tr( "Y" , "first letter of the word 'Year'" );
break;
}
if (i < 2)
@@ -90,7 +108,7 @@ QString DateFormat::toWordString() const
// switch on the relavent 3 bits.
switch((_longOrder >> (i * 3)) & 0x0007) {
case 0x0001:
- buf += QObject::tr( "day" );
+ buf += TimeStringFormat::tr( "day", "in month" );
if (i < 2) {
if ((_shortOrder << ((i+1) * 3)) & 0x0007)
buf += ", ";
@@ -99,12 +117,12 @@ QString DateFormat::toWordString() const
}
break;
case 0x0002:
- buf += QObject::tr( "month" );
+ buf += TimeStringFormat::tr( "month" );
if (i < 2)
buf += " ";
break;
case 0x0004:
- buf += QObject::tr( "year" );
+ buf += TimeStringFormat::tr( "year" );
if (i < 2)
buf += ", ";
break;
@@ -149,64 +167,140 @@ QString DateFormat::numberDate(const QDate &d, int v) const
return buf;
}
+static const char* unTranslatedFullMonthNames[] = {
+ QT_TRANSLATE_NOOP( "QDate", "January" ),
+ QT_TRANSLATE_NOOP( "QDate", "February" ),
+ QT_TRANSLATE_NOOP( "QDate", "March" ),
+ QT_TRANSLATE_NOOP( "QDate", "April" ),
+ QT_TRANSLATE_NOOP( "QDate", "May" ),
+ QT_TRANSLATE_NOOP( "QDate", "June" ),
+ QT_TRANSLATE_NOOP( "QDate", "July" ),
+ QT_TRANSLATE_NOOP( "QDate", "August" ),
+ QT_TRANSLATE_NOOP( "QDate", "September" ),
+ QT_TRANSLATE_NOOP( "QDate", "October" ),
+ QT_TRANSLATE_NOOP( "QDate", "November" ),
+ QT_TRANSLATE_NOOP( "QDate", "December" )
+};
+
+static const char* unTranslatedFullDayNames[] = {
+ QT_TRANSLATE_NOOP( "QDate", "Monday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Tuesday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Wednesday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Thursday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Friday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Saturday" ),
+ QT_TRANSLATE_NOOP( "QDate", "Sunday" )
+};
+
+#ifdef QTOPIA_DESKTOP
+//translations in qt.qm
+static const char* unTranslatedMediumDayNames[] = {
+ "Mon" , "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
+};
+
+static const char* unTranslatedMediumMonthNames[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+#endif
+
+static QString dayname(const QDate& d, bool lng)
+{
+ if (lng && qApp)
+ return qApp->translate("QDate", unTranslatedFullDayNames[d.dayOfWeek()-1]);
+ else {
+#ifdef QTOPIA_DESKTOP
+ if (qApp)
+ return qApp->translate("QDate", unTranslatedMediumDayNames[ d.dayOfWeek()-1]);
+#endif
+ return d.dayName(d.dayOfWeek());
+ }
+}
+
QString DateFormat::wordDate(const QDate &d, int v) const
{
- QString buf = "";
// for each part of the order
- if (v & showWeekDay) {
- QString weekDay = d.dayName(d.dayOfWeek());
- if (!(v & longWord)) {
- weekDay = weekDay.left(3);
- }
- buf += weekDay;
- if ((_longOrder & 0x0007) == 0x0002)
- buf += ' ';
- else
- buf += ", ";
- }
+ QString weekDay;
+ if (v & showWeekDay)
+ weekDay = ::dayname(d,(v & longWord));
+ QString date="";
+ QString sep="";
for (int i = 0; i < 3; i++) {
// switch on the relavent 3 bits.
- switch((_longOrder >> (i * 3)) & 0x0007) {
- case 0x0001:
- if (i==1) {
- buf += QString().sprintf("%02d, ",d.day());
- } else {
- buf += QString().sprintf("%2d",d.day());
- if (separator()=='.') // 2002/1/11
- buf += ". ";
- else
- buf += " ";
- }
+ int field = (_longOrder >> (i * 3)) & 0x0007;
+ if ( field && !date.isEmpty() )
+ date += sep;
+ switch (field) {
+ case 0x0001: // Day
+ {
+ QString daysuffix = TimeStringFormat::tr("@day", "day suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@day' " );
+ if (i==1) {
+ date += QString().sprintf("%02d",d.day());
+ if (daysuffix != "@day")
+ date+=daysuffix;
+ sep = TimeStringFormat::tr(",","day-date separator") + " ";
+ } else {
+ date += QString().sprintf("%2d",d.day());
+ if (daysuffix == "@day") {
+ if (separator()=='.') // 2002/1/11
+ sep = ". ";
+ else
+ sep = " ";
+ } else {
+ date += daysuffix+" ";
+ sep = " ";
+ }
+ }
+ }
break;
- case 0x0002:
+ case 0x0002: // Month
{
- QString monthName = d.monthName(d.month());
- if (!(v & longWord)) {
- monthName = monthName.left(3);
- }
- buf += monthName;
+ QString monthName;
+
+ if (v & longWord)
+ monthName = qApp->translate("QDate", unTranslatedFullMonthNames[d.month()-1] );
+ else {
+#ifdef QTOPIA_DESKTOP
+ monthName = qApp->translate("QDate", unTranslatedMediumMonthNames[d.month()-1] );
+#else
+ monthName = d.monthName( d.month() );
+#endif
+ }
+ date += monthName;
}
- if (i < 2)
- buf += " ";
+ sep = " ";//TimeStringFormat::tr(" ","month-date separator");
break;
- case 0x0004:
+ case 0x0004: // Year
{
int year = d.year();
if (!(v & longNumber))
year = year % 100;
if (year < 10)
- buf += "0";
+ date += "0";
+
+ date += QString::number(year);
+ QString yearsuffix = TimeStringFormat::tr("@year", "year suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@year' " );
+ if (yearsuffix != "@year")
+ date += yearsuffix;
- buf += QString::number(year);
}
- if (i < 2)
- buf += ", ";
+ sep = TimeStringFormat::tr(",","year-date seperator") + " ";
break;
}
}
- return buf;
+
+ QString r = "";
+ if ( weekDay.isEmpty() )
+ r = date;
+ else if ((_longOrder & 0x0007) == 0x0002)
+ r = TimeStringFormat::tr("%1 %2","1=Monday 2=January 12").arg(weekDay).arg(date);
+ else if ( _longOrder )
+ r = TimeStringFormat::tr("%1, %2","1=Monday 2=12 January").arg(weekDay).arg(date);
+ else
+ r = weekDay;
+ return r;
}
#ifndef QT_NO_DATASTREAM
@@ -251,19 +345,19 @@ QString TimeString::shortDate( const QDate &d, DateFormat dtf )
QString TimeString::dateString( const QDate &d, DateFormat dtf )
{
- return QObject::tr( dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord) );
+ return dtf.wordDate(d, DateFormat::longNumber);
}
QString TimeString::longDateString( const QDate &d, DateFormat dtf )
{
- return QObject::tr( dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber
- | DateFormat::longWord) );
+ return dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber
+ | DateFormat::longWord);
}
DateFormat TimeString::currentDateFormat()
{
- return TimeStringFormatKeeper::currentFormat();
+ return TimeStringFormat::currentFormat();
}
@@ -313,28 +407,19 @@ QString TimeString::timeString( const QTime &t, bool ampm, bool seconds )
if ( seconds )
argString = argString.arg( strSec );
if ( hour >= 12 )
- argString = argString.arg( QObject::tr("PM") );
+ argString = argString.arg( TimeStringFormat::tr("PM") );
else
- argString = argString.arg( QObject::tr("AM") );
+ argString = argString.arg( TimeStringFormat::tr("AM") );
return argString;
}
QString TimeString::shortTime( bool ampm, bool seconds )
{
- static const char* const day[] = {
- QT_TRANSLATE_NOOP( "QObject", "Mon" ),
- QT_TRANSLATE_NOOP( "QObject", "Tue" ),
- QT_TRANSLATE_NOOP( "QObject", "Wed" ),
- QT_TRANSLATE_NOOP( "QObject", "Thu" ),
- QT_TRANSLATE_NOOP( "QObject", "Fri" ),
- QT_TRANSLATE_NOOP( "QObject", "Sat" ),
- QT_TRANSLATE_NOOP( "QObject", "Sun" )
- };
// just create a shorter time String
QDateTime dtTmp = QDateTime::currentDateTime();
- QString strTime;
- strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " +
- timeString( dtTmp.time(), ampm, seconds );
+ QString strTime = TimeStringFormat::tr( "%1 %2", "1=Monday 2=12:45" )
+ .arg(::dayname(dtTmp.date(),FALSE))
+ .arg(timeString( dtTmp.time(), ampm, seconds ));
return strTime;
}
@@ -361,5 +446,21 @@ QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf )
{
return dtf.numberDate(d,DateFormat::longNumber);
}
+/*!
+ Returns date/time \a dt as a string,
+ showing year, month, date, hours, minutes, and seconds.
+ \a len determines the length of the resulting string.
+
+ The format, including order depends on the user's settings.
+
+ First availability: Qtopia 1.6
+*/
+//QString TimeString::localYMDHMS( const QDateTime &dt, Length len )
+//{
+// const QDate& d = dt.date();
+// const QTime& t = dt.time();
+// return LocalTimeFormat::tr("%1 %2","date,time").arg(localYMD(d,len)).arg(localHMS(t));
+//}
+
#include "timestring.moc"
diff --git a/library/timestring.h b/library/timestring.h
index 875c8bf..b8d1aea 100644
--- a/library/timestring.h
+++ b/library/timestring.h
@@ -1,16 +1,31 @@
/**********************************************************************
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2006 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License as published by the
+** Free Software Foundation; either version 2 of the License, or (at your
+** option) any later version.
+**
+** A copy of the GNU GPL license version 2 is included in this package as
+** LICENSE.GPL.
**
-** 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.
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+** See the GNU General Public License for more details.
**
+** In addition, as a special exception Trolltech gives permission to link
+** the code of this program with Qtopia applications copyrighted, developed
+** and distributed by Trolltech under the terms of the Qtopia Personal Use
+** License Agreement. You must comply with the GNU General Public License
+** in all respects for all of the code used other than the applications
+** licensed under the Qtopia Personal Use License Agreement. If you modify
+** this file, you may extend this exception to your version of the file,
+** but you are not obligated to do so. If you do not wish to do so, delete
+** this exception statement from your version.
+**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
@@ -22,23 +37,28 @@
#define _TIMESTRING_H_
#include <qdatetime.h>
#include <qstring.h>
+#include <qarray.h>
#if (QT_VERSION-0 >= 0x030000)
#define DateFormat QPEDateFormat
#endif
+#include <qtopia/qpeglobal.h>
+
+class QObject;
+
// return a string with the time based on whether or not you want
// you want it in 12 hour form. if ampm is true, then return
// it in 12 hour (am/pm) form otherwise return it in 24 hour form
// in theory Qt 3,0 handles this better (hopefully obsoleteing this)
-class DateFormat
+class DateFormat
{
public:
- // date format type 001,010,100 = day month year
+ // date format type 1,2,4 = day,month,year
enum Order {
- DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3)
- MonthDayYear = 0x010A,
- YearMonthDay = 0x0054
+ DayMonthYear = 0421, // right-to-left
+ MonthDayYear = 0412,
+ YearMonthDay = 0124
};
DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so),
@@ -99,34 +119,48 @@ class TimeString
{
public:
- //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601,
+ //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601,
//YearMonthDay = ISO8601 };
-/**
- * @name Convience functions which use currentDateFormat
- */
-//@{
- static QString shortDate( const QDate &d )
+
+//private:
+ static QString shortDate( const QDate &d )
{ return shortDate( d, currentDateFormat() ); }
static QString dateString( const QDate &d )
{ return dateString( d, currentDateFormat() ); }
static QString longDateString( const QDate &d )
{ return longDateString( d, currentDateFormat() ); }
-//@}
static QString dateString( const QDateTime &dt, bool ampm, bool seconds )
{ return dateString( dt, ampm, seconds, currentDateFormat() ); }
+public:
+ enum Length { Short, Medium, Long };
+ static QString localH( int hour );
+ static QString localHM( const QTime & );
+ static QString localHM( const QTime &, Length ); // qtopia 2.1.0
+ static QString localHMS( const QTime & );
+ static QString localHMDayOfWeek( const QDateTime &t );
+ static QString localHMSDayOfWeek( const QDateTime &t );
+ static QString localMD( const QDate &, Length=Medium );
+ static QString localYMD( const QDate &, Length=Medium );
+ static QString localYMDHMS( const QDateTime &, Length=Medium );
+ static QString localDayOfWeek( const QDate&, Length=Medium );
+ static QString localDayOfWeek( int day1to7, Length=Medium );
+
+ static QString hourString( int hour, bool ampm );
+ static bool currentAMPM();
+ static DateFormat currentDateFormat();
+ static QArray<DateFormat> formatOptions(); // qtopia 1.6.0
+
+ static void connectChange(QObject*,const char* member);
+ static void disconnectChange(QObject*,const char* member);
- /** @name Do not use as they don't honor system settings for AMPM
- *
- */
- //@{
- static QString dateString( const QDateTime &t, bool ampm = false );
+ // Not recommended to call these (they don't honor system ampm)
+ static QString dateString( const QDateTime &t, bool ampm );
static QString timeString( const QTime &t, bool ampm, bool seconds );
- static QString timeString( const QTime &t, bool ampm = false );
+ static QString timeString( const QTime &t, bool ampm );
static QString shortTime( bool ampm, bool seconds );
- static QString shortTime( bool ampm = false );
- //@}
+ static QString shortTime( bool ampm );
static QString numberDateString( const QDate &d, DateFormat );
static QString numberDateString( const QDate &d )
@@ -139,11 +173,9 @@ public:
static QString dateString( const QDate &, DateFormat );
static QString longDateString( const QDate &, DateFormat );
- static DateFormat currentDateFormat();
-
private:
static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat );
-
+
};