summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/firstuse.cpp9
-rw-r--r--libopie2/opiepim/core/opimevent.cpp2
-rw-r--r--library/backend/event.cpp2
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp18
-rw-r--r--noncore/games/qasteroids/view.cpp7
-rw-r--r--noncore/games/solitaire/cardpile.h2
6 files changed, 25 insertions, 15 deletions
diff --git a/core/launcher/firstuse.cpp b/core/launcher/firstuse.cpp
index acddeea..8344787 100644
--- a/core/launcher/firstuse.cpp
+++ b/core/launcher/firstuse.cpp
@@ -1,513 +1,514 @@
/**********************************************************************
** 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.
**
**********************************************************************/
// I need access to some things you don't normally get access to.
#ifndef _MSC_VER
//### revise to allow removal of translators under MSVC
#define private public
#define protected public
#endif
#include "firstuse.h"
#include "inputmethods.h"
#include "applauncher.h"
#include "serverapp.h"
#include "calibrate.h"
#include "documentlist.h"
/* OPIE */
#include <opie2/odebug.h>
#include <qtopia/resource.h>
#include <qtopia/qcopenvelope_qws.h>
#include <qtopia/config.h>
#include <qtopia/fontmanager.h>
using namespace Opie::Core;
/* QT */
#include <qfile.h>
#include <qpainter.h>
#include <qsimplerichtext.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qtimer.h>
#if defined( Q_WS_QWS )
#include <qwsdisplay_qws.h>
#include <qgfx_qws.h>
#endif
/* STD */
#include <stdlib.h>
#include <sys/types.h>
#if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
#include <unistd.h>
#endif
-struct {
- bool enabled;
+struct settingsTable_t {
+ bool enabled : 1;
const char *app;
const char *start;
const char *stop;
const char *desc;
-}
-settingsTable [] =
+};
+
+static settingsTable_t settingsTable [] =
{
{ FALSE, "language", "raise()", "accept()", // No tr
QT_TR_NOOP("Language") },
{ FALSE, "doctab", "raise()", "accept()", // No tr
QT_TR_NOOP("DocTab") },
#ifndef Q_OS_WIN32
{ FALSE, "systemtime", "raise()", "accept()", // No tr
QT_TR_NOOP("Time and Date") },
#endif
{ FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr
QT_TR_NOOP("Personal Information") },
{ FALSE, 0, 0, 0, 0 }
};
FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) :
QDialog( parent, name, TRUE, wf),
transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1),
waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE)
{
ServerApplication::allowRestart = FALSE;
// we force our height beyound the maximum (which we set anyway)
QRect desk = qApp->desktop()->geometry();
setGeometry( 0, 0, desk.width(), desk.height() );
connect(qwsServer, SIGNAL(newChannel(const QString&)),
this, SLOT(newQcopChannel(const QString&)));
// Create a DocumentList so appLauncher has appLnkSet to search
docList = new DocumentList( 0, FALSE );
appLauncher = new AppLauncher( this );
connect( appLauncher, SIGNAL(terminated(int,const QString&)),
this, SLOT(terminated(int,const QString&)) );
// more hackery
// I will be run as either the main server or as part of the main server
QWSServer::setScreenSaverIntervals(0);
loadPixmaps();
//check if there is a language program
#ifndef Q_OS_WIN32
QString exeSuffix;
#else
QString exeSuffix(".exe");
#endif
for ( int i = 0; settingsTable[i].app; i++ ) {
QString file = QPEApplication::qpeDir() + "bin/";
file += settingsTable[i].app;
file += exeSuffix;
if ( QFile::exists(file) )
settingsTable[i].enabled = TRUE;
}
setFocusPolicy(NoFocus);
taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader);
inputMethods = new InputMethods(taskBar);
connect(inputMethods, SIGNAL(inputToggled(bool)),
this, SLOT(calcMaxWindowRect()));
back = new QPushButton(tr("<< Back"), taskBar);
back->setFocusPolicy(NoFocus);
connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) );
next = new QPushButton(tr("Next >>"), taskBar);
next->setFocusPolicy(NoFocus);
connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) );
// need to set the geom to lower corner
QSize sz = inputMethods->sizeHint();
int buttonWidth = (width() - sz.width()) / 2;
int x = 0;
controlHeight = back->sizeHint().height();
inputMethods->setGeometry(0,0, sz.width(), controlHeight );
x += sz.width();
back->setGeometry(x, 0, buttonWidth, controlHeight);
x += buttonWidth;
next->setGeometry(x, 0, buttonWidth, controlHeight);
taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight);
taskBar->hide();
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
odebug << "Setting up QCop to QPE/System" << oendl;
QCopChannel* sysChannel = new QCopChannel( "QPE/System", this );
connect(sysChannel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT(message(const QCString&,const QByteArray&)) );
#endif
calcMaxWindowRect();
m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false;
if ( m_calHandler) {
if ( !QFile::exists("/etc/pointercal") ) {
needCalibrate = TRUE;
grabMouse();
}
}
Config config("locale");
config.setGroup( "Language");
lang = config.readEntry( "Language", "en");
defaultFont = font();
//###language/font hack; should look it up somewhere
#ifdef Q_WS_QWS
if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
QFont fn = FontManager::unicodeFont( FontManager::Proportional );
qApp->setFont( fn, TRUE );
}
#endif
}
FirstUse::~FirstUse()
{
delete appLauncher;
delete docList;
delete taskBar;
ServerApplication::allowRestart = TRUE;
}
void FirstUse::calcMaxWindowRect()
{
#ifdef Q_WS_QWS
QRect wr;
int displayWidth = qApp->desktop()->width();
QRect ir = inputMethods->inputRect();
if ( ir.isValid() ) {
wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 );
} else {
wr.setCoords( 0, 0, displayWidth-1,
qApp->desktop()->height() - controlHeight-1);
}
#if QT_VERSION < 0x030000
QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,
QSize(qt_screen->width(),qt_screen->height()))
);
#else
QWSServer::setMaxWindowRect( wr );
#endif
#endif
}
/* cancel current dialog, and bring up next */
void FirstUse::nextDialog()
{
int prevApp = currApp;
do {
currApp++;
odebug << "currApp = " << currApp << "" << oendl;
if ( settingsTable[currApp].app == 0 ) {
if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
// The last application is still running.
// Tell it to stop, and when its done we'll come back
// to nextDialog and exit.
odebug << "Waiting for " << settingsTable[prevApp].app << " to exit" << oendl;
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
settingsTable[prevApp].stop );
currApp = prevApp;
} else {
odebug << "Done!" << oendl;
Config config( "qpe" );
config.setGroup( "Startup" );
config.writeEntry( "FirstUse", FALSE );
QPixmap pix = Resource::loadPixmap("bigwait");
QLabel *lblWait = new QLabel(0, "wait hack!", // No tr
QWidget::WStyle_Customize | QWidget::WDestructiveClose |
QWidget::WStyle_NoBorder | QWidget::WStyle_Tool |
QWidget::WStyle_StaysOnTop);
lblWait->setPixmap( pix );
lblWait->setAlignment( QWidget::AlignCenter );
lblWait->setGeometry( qApp->desktop()->geometry() );
lblWait->show();
qApp->processEvents();
QTimer::singleShot( 1000, lblWait, SLOT(close()) );
repaint();
close();
ServerApplication::allowRestart = TRUE;
}
return;
}
} while ( !settingsTable[currApp].enabled );
if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) {
odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl;
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
settingsTable[prevApp].stop );
waitForExit = prevApp;
} else {
odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
settingsTable[currApp].start );
waitingForLaunch = TRUE;
}
updateButtons();
}
/* accept current dialog and bring up previous */
void FirstUse::previousDialog()
{
int prevApp = currApp;
do {
currApp--;
if ( currApp < 0 ) {
currApp = prevApp;
return;
}
} while ( !settingsTable[currApp].enabled );
if ( prevApp >= 0 ) {
odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl;
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app,
settingsTable[prevApp].stop );
/*
if (settingsTable[prevApp].app == QString("systemtime"))
QCopEnvelope e("QPE/Application/citytime", "close()");
*/
waitForExit = prevApp;
} else {
odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
settingsTable[currApp].start );
waitingForLaunch = TRUE;
}
updateButtons();
}
void FirstUse::message(const QCString &msg, const QByteArray &data)
{
QDataStream stream( data, IO_ReadOnly );
if ( msg == "timeChange(QString)" ) {
QString t;
stream >> t;
if ( t.isNull() )
unsetenv("TZ");
else
setenv( "TZ", t.latin1(), 1 );
}
}
void FirstUse::terminated( int, const QString &app )
{
odebug << "--- terminated: " << app << "" << oendl;
if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) {
odebug << "Startup: " << settingsTable[currApp].app << "" << oendl;
if ( settingsTable[waitForExit].app == "language" ) { // No tr
Config config("locale");
config.setGroup( "Language");
QString l = config.readEntry( "Language", "en");
if ( l != lang ) {
reloadLanguages();
needRestart = TRUE;
lang = l;
}
}
QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app,
settingsTable[currApp].start );
waitingForLaunch = TRUE;
updateButtons();
repaint();
waitForExit = -1;
} else if ( settingsTable[currApp].app == app ) {
nextDialog();
} else {
back->setEnabled(TRUE);
next->setEnabled(TRUE);
}
}
void FirstUse::newQcopChannel(const QString& channelName)
{
odebug << "channel " << channelName.data() << " added" << oendl;
QString prefix("QPE/Application/");
if (channelName.startsWith(prefix)) {
QString appName = channelName.mid(prefix.length());
if ( currApp >= 0 && appName == settingsTable[currApp].app ) {
odebug << "Application: " << settingsTable[currApp].app << " started" << oendl;
waitingForLaunch = FALSE;
updateButtons();
repaint();
} else if (appName != "quicklauncher") {
back->setEnabled(FALSE);
next->setEnabled(FALSE);
}
}
}
void FirstUse::reloadLanguages()
{
// read language from config file. Waiting on QCop takes too long.
Config config("locale");
config.setGroup( "Language");
QString l = config.readEntry( "Language", "en");
QString cl = getenv("LANG");
owarn << "language message - " + l << oendl;
// setting anyway...
if (l.isNull() )
unsetenv( "LANG" );
else {
owarn << "and its not null" << oendl;
setenv( "LANG", l.latin1(), 1 );
}
#ifndef QT_NO_TRANSLATION
// clear old translators
#ifndef _MSC_VER
//### revise to allow removal of translators under MSVC
if(qApp->translators) {
qApp->translators->setAutoDelete(TRUE);
delete (qApp->translators);
qApp->translators = 0;
}
#endif
// load translation tables
transApp = new QTranslator(qApp);
QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm";
owarn << "loading " + tfn << oendl;
if ( transApp->load(tfn) ) {
owarn << "installing translator" << oendl;
qApp->installTranslator( transApp );
} else {
delete transApp;
transApp = 0;
}
transLib = new QTranslator(qApp);
tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm";
owarn << "loading " + tfn << oendl;
if ( transLib->load(tfn) ) {
owarn << "installing translator library" << oendl;
qApp->installTranslator( transLib );
} else {
delete transLib;
transLib = 0;
}
loadPixmaps();
//###language/font hack; should look it up somewhere
#ifdef Q_WS_QWS
if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) {
QFont fn = FontManager::unicodeFont( FontManager::Proportional );
qApp->setFont( fn, TRUE );
} else {
qApp->setFont( defaultFont, TRUE );
}
#endif
#endif
}
void FirstUse::paintEvent( QPaintEvent * )
{
QPainter p( this );
p.drawPixmap(0,0, splash);
QFont f = p.font();
f.setPointSize(15);
f.setItalic(FALSE);
f.setBold(FALSE);
p.setFont(f);
if ( currApp < 0 ) {
drawText(p, tr( "Tap anywhere on the screen to continue." ));
} else if ( settingsTable[currApp].app ) {
if ( waitingForLaunch )
drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) );
} else {
drawText(p, tr("Please wait..."));
}
}
void FirstUse::loadPixmaps()
{
splash.convertFromImage( Resource::loadImage("launcher/firstuse")
.smoothScale( width(), height() ) );
setBackgroundPixmap(splash);
}
void FirstUse::drawText(QPainter &p, const QString &text)
{
QString altered = "<CENTER>" + text + "</CENTER>";
QSimpleRichText rt(altered, p.font());
rt.setWidth(width() - 20);
int h = (height() * 3) / 10; // start at 30%
if (rt.height() < height() / 2)
h += ((height() / 2) - rt.height()) / 2;
rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette());
}
void FirstUse::updateButtons()
{
if ( currApp >= 0 ) {
taskBar->show();
}
int i = currApp-1;
while ( i >= 0 && !settingsTable[i].enabled )
i--;
back->setText(tr("<< Back"));
back->setEnabled( i >= 0 && !waitingForLaunch );
i = currApp+1;
while ( settingsTable[i].app && !settingsTable[i].enabled )
i++;
if ( !settingsTable[i].app )
next->setText(tr("Finish"));
else
next->setText(tr("Next >>"));
next->setEnabled( !waitingForLaunch );
}
void FirstUse::keyPressEvent( QKeyEvent *e )
{
// Allow cancelling at first dialog, in case display is broken.
if ( e->key() == Key_Escape && currApp < 0 )
QDialog::keyPressEvent(e);
}
void FirstUse::mouseReleaseEvent( QMouseEvent * )
{
if ( currApp < 0 ) {
if ( m_calHandler && needCalibrate ) {
releaseMouse();
Calibrate *cal = new Calibrate;
cal->exec();
delete cal;
}
nextDialog();
}
}
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index c656c3d..7bc6c32 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -1,585 +1,585 @@
/*
This file is part of the Opie Project
Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. 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
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimevent.h"
/* OPIE */
#include <opie2/opimrecurrence.h>
#include <opie2/opimresolver.h>
#include <opie2/opimnotifymanager.h>
#include <opie2/odebug.h>
#include <qpe/categories.h>
#include <qpe/stringutil.h>
/* QT */
namespace Opie
{
int OCalendarHelper::week( const QDate& date )
{
// Calculates the week this date is in within that
// month. Equals the "row" is is in in the month view
int week = 1;
QDate tmp( date.year(), date.month(), 1 );
if ( date.dayOfWeek() < tmp.dayOfWeek() )
++week;
week += ( date.day() - 1 ) / 7;
return week;
}
int OCalendarHelper::ocurrence( const QDate& date )
{
// calculates the number of occurrances of this day of the
// week till the given date (e.g 3rd Wednesday of the month)
return ( date.day() - 1 ) / 7 + 1;
}
int OCalendarHelper::dayOfWeek( char day )
{
int dayOfWeek = 1;
char i = OPimRecurrence::MON;
- while ( !( i & day ) && i <= OPimRecurrence::SUN )
+ while ( !( i & day ) && i <= static_cast<char>(OPimRecurrence::SUN) )
{
i <<= 1;
++dayOfWeek;
}
return dayOfWeek;
}
int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
{
return ( second.year() - first.year() ) * 12 +
second.month() - first.month();
}
struct OPimEvent::Data : public QShared
{
Data() : QShared()
{
child = 0;
recur = 0;
manager = 0;
isAllDay = false;
parent = 0;
}
~Data()
{
delete manager;
delete recur;
}
QString description;
QString location;
OPimNotifyManager* manager;
OPimRecurrence* recur;
QString note;
QDateTime created;
QDateTime start;
QDateTime end;
bool isAllDay : 1;
QString timezone;
QArray<int>* child;
int parent;
};
OPimEvent::OPimEvent( int uid )
: OPimRecord( uid )
{
data = new Data;
}
OPimEvent::OPimEvent( const OPimEvent& ev )
: OPimRecord( ev ), data( ev.data )
{
data->ref();
}
OPimEvent::OPimEvent( const QMap<int, QString> map )
: OPimRecord( 0 )
{
data = new Data;
fromMap( map );
}
OPimEvent::~OPimEvent()
{
if ( data->deref() )
{
delete data;
data = 0;
}
}
OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
{
if ( this == &ev ) return * this;
OPimRecord::operator=( ev );
ev.data->ref();
deref();
data = ev.data;
return *this;
}
QString OPimEvent::description() const
{
return data->description;
}
void OPimEvent::setDescription( const QString& description )
{
changeOrModify();
data->description = description;
}
void OPimEvent::setLocation( const QString& loc )
{
changeOrModify();
data->location = loc;
}
QString OPimEvent::location() const
{
return data->location;
}
OPimNotifyManager &OPimEvent::notifiers() const
{
// I hope we can skip the changeOrModify here
// the notifier should take care of it
// and OPimNotify is shared too
if ( !data->manager )
data->manager = new OPimNotifyManager;
return *data->manager;
}
bool OPimEvent::hasNotifiers() const
{
if ( !data->manager )
return false;
if ( data->manager->reminders().isEmpty() &&
data->manager->alarms().isEmpty() )
return false;
return true;
}
OPimRecurrence OPimEvent::recurrence() const
{
if ( !data->recur )
data->recur = new OPimRecurrence;
return *data->recur;
}
void OPimEvent::setRecurrence( const OPimRecurrence& rec )
{
changeOrModify();
if ( data->recur )
( *data->recur ) = rec;
else
data->recur = new OPimRecurrence( rec );
}
bool OPimEvent::hasRecurrence() const
{
if ( !data->recur ) return false;
return data->recur->doesRecur();
}
QString OPimEvent::note() const
{
return data->note;
}
void OPimEvent::setNote( const QString& note )
{
changeOrModify();
data->note = note;
}
QDateTime OPimEvent::createdDateTime() const
{
return data->created;
}
void OPimEvent::setCreatedDateTime( const QDateTime& time )
{
changeOrModify();
data->created = time;
}
QDateTime OPimEvent::startDateTime() const
{
if ( data->isAllDay )
return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
return data->start;
}
QDateTime OPimEvent::startDateTimeInZone() const
{
/* if no timezone, or all day event or if the current and this timeZone match... */
if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
OPimTimeZone zone( data->timezone );
return zone.toDateTime( data->start, OPimTimeZone::current() );
}
void OPimEvent::setStartDateTime( const QDateTime& dt )
{
changeOrModify();
data->start = dt;
}
QDateTime OPimEvent::endDateTime() const
{
/*
* if all Day event the end time needs
* to be on the same day as the start
*/
if ( data->isAllDay ) {
QDate end = data->end.isValid() ? data->end.date() : data->start.date() ;
return QDateTime( end, QTime( 23, 59, 59 ) );
}
return data->end;
}
QDateTime OPimEvent::endDateTimeInZone() const
{
/* if no timezone, or all day event or if the current and this timeZone match... */
if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
OPimTimeZone zone( data->timezone );
return zone.toDateTime( data->end, OPimTimeZone::current() );
}
void OPimEvent::setEndDateTime( const QDateTime& dt )
{
changeOrModify();
data->end = dt;
}
bool OPimEvent::isMultipleDay() const
{
return data->end.date().day() - data->start.date().day();
}
bool OPimEvent::isAllDay() const
{
return data->isAllDay;
}
void OPimEvent::setAllDay( bool allDay )
{
changeOrModify();
data->isAllDay = allDay;
}
void OPimEvent::setTimeZone( const QString& tz )
{
changeOrModify();
data->timezone = tz;
}
QString OPimEvent::timeZone() const
{
if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" );
return data->timezone;
}
bool OPimEvent::match( const QRegExp& re ) const
{
if ( re.match( data->description ) != -1 )
{
setLastHitField( Qtopia::DatebookDescription );
return true;
}
if ( re.match( data->note ) != -1 )
{
setLastHitField( Qtopia::Note );
return true;
}
if ( re.match( data->location ) != -1 )
{
setLastHitField( Qtopia::Location );
return true;
}
if ( re.match( data->start.toString() ) != -1 )
{
setLastHitField( Qtopia::StartDateTime );
return true;
}
if ( re.match( data->end.toString() ) != -1 )
{
setLastHitField( Qtopia::EndDateTime );
return true;
}
return false;
}
QString OPimEvent::toRichText() const
{
QString text, value;
// description
text += "<b><h3><img src=\"datebook/DateBook\">";
if ( !description().isEmpty() )
{
text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
}
text += "</h3></b><br><hr><br>";
// location
if ( !( value = location() ).isEmpty() )
{
text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
text += Qtopia::escapeString( value ) + "<br>";
}
// all day event
if ( isAllDay() )
{
text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
}
// multiple day event
else if ( isMultipleDay () )
{
text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
}
// start & end times
else
{
// start time
if ( startDateTime().isValid() )
{
text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
text += Qtopia::escapeString( startDateTime().toString() ).
replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
}
// end time
if ( endDateTime().isValid() )
{
text += "<b>" + QObject::tr( "End:" ) + "</b> ";
text += Qtopia::escapeString( endDateTime().toString() ).
replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
}
}
// categories
if ( categoryNames( "Calendar" ).count() )
{
text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
text += categoryNames( "Calendar" ).join( ", " );
text += "<br>";
}
//notes
if ( !note().isEmpty() )
{
text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
text += note();
// text += Qtopia::escapeString(note() ).
// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
}
return text;
}
QString OPimEvent::toShortText() const
{
QString text;
text += QString::number( startDateTime().date().day() );
text += ".";
text += QString::number( startDateTime().date().month() );
text += ".";
text += QString::number( startDateTime().date().year() );
text += " ";
text += QString::number( startDateTime().time().hour() );
text += ":";
text += QString::number( startDateTime().time().minute() );
text += " - ";
text += description();
return text;
}
QString OPimEvent::type() const
{
return QString::fromLatin1( "OPimEvent" );
}
QString OPimEvent::recordField( int /*id */ ) const
{
return QString::null;
}
int OPimEvent::rtti() const
{
return OPimResolver::DateBook;
}
bool OPimEvent::loadFromStream( QDataStream& )
{
return true;
}
bool OPimEvent::saveToStream( QDataStream& ) const
{
return true;
}
void OPimEvent::changeOrModify()
{
if ( data->count != 1 )
{
data->deref();
Data* d2 = new Data;
d2->description = data->description;
d2->location = data->location;
if ( data->manager )
d2->manager = new OPimNotifyManager( *data->manager );
if ( data->recur )
d2->recur = new OPimRecurrence( *data->recur );
d2->note = data->note;
d2->created = data->created;
d2->start = data->start;
d2->end = data->end;
d2->isAllDay = data->isAllDay;
d2->timezone = data->timezone;
d2->parent = data->parent;
if ( data->child )
{
d2->child = new QArray<int>( *data->child );
d2->child->detach();
}
data = d2;
}
}
void OPimEvent::deref()
{
if ( data->deref() )
{
delete data;
data = 0;
}
}
// Exporting Event data to map. Using the same
// encoding as ODateBookAccessBackend_xml does..
// Thus, we could remove the stuff there and use this
// for it and for all other places..
// Encoding should happen at one place, only ! (eilers)
QMap<int, QString> OPimEvent::toMap() const
{
QMap<int, QString> retMap;
retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
if ( notifiers().alarms().count() ){
// Currently we just support one alarm.. (eilers)
OPimAlarm alarm = notifiers().alarms() [ 0 ];
retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
}
/* either use UTC timeZone or current() if there is was a timezone set */
OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
if ( parent() )
retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
if ( children().count() )
{
QArray<int> childr = children();
QString buf;
for ( uint i = 0; i < childr.count(); i++ )
{
if ( i != 0 ) buf += " ";
buf += QString::number( childr[ i ] );
}
retMap.insert( OPimEvent::FRecChildren, buf );
diff --git a/library/backend/event.cpp b/library/backend/event.cpp
index 90860e8..abc420b 100644
--- a/library/backend/event.cpp
+++ b/library/backend/event.cpp
@@ -1,914 +1,914 @@
/**********************************************************************
** 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 "event.h"
#include "qfiledirect_p.h"
#include <qtopia/timeconversion.h>
#include <qtopia/stringutil.h>
#include <qtopia/private/recordfields.h>
#include <qbuffer.h>
#include <time.h>
#include "vobject_p.h"
#include <stdio.h>
using namespace Qtopia;
static void write( QString& buf, const Event::RepeatPattern &r )
{
buf += " rtype=\"";
switch ( r.type ) {
case Event::Daily:
buf += "Daily";
break;
case Event::Weekly:
buf += "Weekly";
break;
case Event::MonthlyDay:
buf += "MonthlyDay";
break;
case Event::MonthlyDate:
buf += "MonthlyDate";
break;
case Event::Yearly:
buf += "Yearly";
break;
default:
buf += "NoRepeat";
break;
}
buf += "\"";
if ( r.days > 0 )
buf += " rweekdays=\"" + QString::number( static_cast<int>( r.days ) ) + "\"";
if ( r.position != 0 )
buf += " rposition=\"" + QString::number( r.position ) + "\"";
buf += " rfreq=\"" + QString::number( r.frequency ) + "\"";
buf += " rhasenddate=\"" + QString::number( static_cast<int>( r.hasEndDate ) ) + "\"";
if ( r.hasEndDate )
buf += " enddt=\""
+ QString::number( r.endDateUTC ? r.endDateUTC : time( 0 ) )
+ "\"";
buf += " created=\"" + QString::number( r.createTime ) + "\"";
}
Qtopia::UidGen Event::sUidGen( Qtopia::UidGen::Qtopia );
/*!
\class Event event.h
\brief The Event class holds the data of a calendar event.
This data includes descriptive data of the event and schedualing information.
\ingroup qtopiaemb
\ingroup qtopiadesktop
*/
/*!
\class Event::RepeatPattern
\class The Event::RepeatPattern class is internal.
\internal
*/
/*!
\enum Event::Days
\internal
*/
/*!
\enum Event::Type
\internal
*/
/*!
\enum Event::SoundTypeChoice
This enum type defines what kind of sound is made when an alarm occurs
for an event. The currently defined types are:
<ul>
<li>\c Silent - No sound is produced.
<li>\c Loud - A loud sound is produced.
</ul>
*/
/*!
\fn bool Event::operator<( const Event & ) const
\internal
*/
/*!
\fn bool Event::operator<=( const Event & ) const
\internal
*/
/*!
\fn bool Event::operator!=( const Event & ) const
\internal
*/
/*!
\fn bool Event::operator>( const Event & ) const
\internal
*/
/*!
\fn bool Event::operator>=( const Event & ) const
\internal
*/
/*!
\enum Event::RepeatType
This enum defines how a event will repeat, if at all.
<ul>
<li>\c NoRepeat - Event does not repeat.
<li>\c Daily - Event occurs every n days.
<li>\c Weekly - Event occurs every n weeks.
<li>\c MonthlyDay - Event occurs every n months. Event will always occur in
the same week and same day of week as the first event.
<li>\c MonthlyDate - Event occurs every n months. Event will always occur
on the same day of the month as the first event.
<li>\c Yearly - Event occurs every n years.
</ul>
*/
/*!
\fn bool Event::isAllDay() const
Returns TRUE if the event is an all day event. Otherwise returns FALSE.
*/
/*!
\fn void Event::setAllDay(bool allday)
If \a allday is TRUE, will set the event to be an all day event.
Otherwise sets the event to not be an all day event.
\warning This function may affect the start and end times of the event.
*/
/*!
\fn QDateTime Event::start(bool) const
Returns the start date and time of the first occurance of the event.
*/
/*!
\fn QDateTime Event::end(bool) const
Returns the end date and time of the first occurance of the event.
*/
/*!
\fn time_t Event::startTime() const
\internal
*/
/*!
\fn time_t Event::endTime() const
\internal
*/
/*!
\fn void Event::setAlarm(int delay, SoundTypeChoice s)
Sets the alarm delay of the event to \a delay and the sound type of the
alarm to \a s.
*/
/*!
\fn void Event::clearAlarm()
Clears the alarm for the event.
*/
/*!
\fn int Event::alarmDelay() const
Returns the delay in minutes between the alarm for an event and the
start of the event.
*/
/*!
\fn Event::RepeatType Event::repeatType() const
Returns the repeat pattern type for the event.
\sa frequency()
*/
/*!
\fn int Event::weekOffset() const
Returns the number of weeks from the start of the month that this event
occurs.
*/
/*!
\fn QDate Event::repeatTill() const
Returns the date that the event will continue to repeat until. If the event
repeats forever the value returned is undefined.
\sa repeatForever()
*/
/*!
\fn bool Event::repeatForever() const
Returns FALSE if there is a date set for the event to continue until.
Otherwise returns TRUE.
*/
/*!
\fn bool Event::doRepeat() const
\internal
*/
/*!
\fn bool Event::repeatOnWeekDay(int day) const
Returns TRUE if the event has a RepeatType of Weekly and is set to occur on
\a day each week. Otherwise returns FALSE.
\sa QDate::dayName()
*/
/*!
\fn void Event::setRepeatOnWeekDay(int day, bool enable)
If \a enable is TRUE then sets the event to occur on \a day each week.
Otherwise sets the event not to occur on \a day.
\warning this function is only relavent for a event with RepeatType of
Weekly.
\sa QDate::dayName()
*/
/*!
\fn int Event::frequency() const
Returns how often the event repeats.
\sa repeatType()
*/
/*!
\fn void Event::setRepeatType(RepeatType t)
Sets the repeat pattern type of the event to \a t.
\sa setFrequency()
*/
/*!
\fn void Event::setFrequency(int n)
Sets how often the event occurs with in its repeat pattern.
\sa setRepeatType()
*/
/*!
\fn void Event::setRepeatTill(const QDate &d)
Sets the event to repeat until \a d.
*/
/*!
\fn void Event::setRepeatForever(bool enable)
If \a enable is TRUE, sets the event to repeat forever. Otherwise
sets the event to stop repeating at some date.
\warning This function may affect the specific date the event will repeat
till.
*/
/*!
\fn bool Event::match(const QRegExp &r) const
Returns TRUE if the event matches the regular expression \a r.
Otherwise returns FALSE.
*/
/*!
\fn char Event::day(int)
\internal
*/
/*!
Creates a new, empty event.
*/
Event::Event() : Record()
{
startUTC = endUTC = time( 0 );
typ = Normal;
hAlarm = FALSE;
hRepeat = FALSE;
aMinutes = 0;
aSound = Silent;
pattern.type = NoRepeat;
pattern.frequency = -1;
}
/*!
\internal
*/
Event::Event( const QMap<int, QString> &map )
{
setDescription( map[DatebookDescription] );
setLocation( map[Location] );
setCategories( idsFromString( map[DatebookCategory] ) );
setTimeZone( map[TimeZone] );
setNotes( map[Note] );
setStart( TimeConversion::fromUTC( map[StartDateTime].toUInt() ) );
setEnd( TimeConversion::fromUTC( map[EndDateTime].toUInt() ) );
setType( (Event::Type) map[DatebookType].toInt() );
setAlarm( ( map[HasAlarm] == "1" ? TRUE : FALSE ), map[AlarmTime].toInt(), (Event::SoundTypeChoice)map[SoundType].toInt() );
Event::RepeatPattern p;
p.type = (Event::RepeatType) map[ RepeatPatternType ].toInt();
p.frequency = map[ RepeatPatternFrequency ].toInt();
p.position = map[ RepeatPatternPosition ].toInt();
p.days = map[ RepeatPatternDays ].toInt();
p.hasEndDate = map[ RepeatPatternHasEndDate ].toInt();
p.endDateUTC = map[ RepeatPatternEndDate ].toUInt();
setRepeat( p );
setUid( map[ DatebookUid ].toInt() );
}
/*!
Destroys an event.
*/
Event::~Event()
{
}
/*!
\internal
*/
int Event::week( const QDate& date )
{
// Calculates the week this date is in within that
// month. Equals the "row" is is in in the month view
int week = 1;
QDate tmp( date.year(), date.month(), 1 );
if ( date.dayOfWeek() < tmp.dayOfWeek() )
++week;
week += ( date.day() - 1 ) / 7;
return week;
}
/*!
\internal
*/
int Event::occurrence( const QDate& date )
{
// calculates the number of occurrances of this day of the
// week till the given date (e.g 3rd Wednesday of the month)
return ( date.day() - 1 ) / 7 + 1;
}
/*!
\internal
*/
int Event::dayOfWeek( char day )
{
int dayOfWeek = 1;
char i = Event::MON;
- while ( !( i & day ) && i <= Event::SUN ) {
+ while ( !( i & day ) && i <= static_cast<char>(Event::SUN) ) {
i <<= 1;
++dayOfWeek;
}
return dayOfWeek;
}
/*!
\internal
*/
int Event::monthDiff( const QDate& first, const QDate& second )
{
return ( second.year() - first.year() ) * 12 +
second.month() - first.month();
}
/*!
\internal
*/
QMap<int, QString> Event::toMap() const
{
QMap<int, QString> m;
if ( !description().isEmpty() )
m.insert( DatebookDescription, description() );
if ( !location().isEmpty() )
m.insert ( Location, location() );
if ( categories().count() )
m.insert ( DatebookCategory, idsToString( categories() ) );
if ( !timeZone().isEmpty() )
m.insert ( TimeZone, timeZone() );
if ( !notes().isEmpty() )
m.insert ( Note, notes() );
m.insert ( StartDateTime, QString::number( TimeConversion::toUTC( start() ) ) );
m.insert ( EndDateTime, QString::number( TimeConversion::toUTC( end() ) ) );
m.insert ( DatebookType, QString::number( (int)type() ) );
m.insert ( HasAlarm, ( hasAlarm() ? "1" : "0" ) );
m.insert ( SoundType, QString::number( (int)alarmSound() ) );
m.insert ( AlarmTime, QString::number( alarmTime() ) );
m.insert ( RepeatPatternType, QString::number( static_cast<int>( repeatPattern().type ) ) );
m.insert ( RepeatPatternFrequency, QString::number( repeatPattern().frequency ) );
m.insert ( RepeatPatternPosition, QString::number( repeatPattern().position ) );
m.insert ( RepeatPatternDays, QString::number( repeatPattern().days ) );
m.insert ( RepeatPatternHasEndDate, QString::number( static_cast<int>( repeatPattern().hasEndDate ) ) );
m.insert ( RepeatPatternEndDate, QString::number( repeatPattern().endDateUTC ) );
m.insert( DatebookUid, QString::number( uid()) );
return m;
}
/*!
\internal
*/
void Event::setRepeat( const RepeatPattern &p )
{
setRepeat( p.type != NoRepeat, p );
}
/*!
Sets the description of the event to \a s.
*/
void Event::setDescription( const QString &s )
{
descript = s;
}
/*!
Sets the location of the event to \a s.
*/
void Event::setLocation( const QString &s )
{
locat = s;
}
// void Event::setCategory( const QString &s )
// {
// categ = s;
// }
/*!
\internal
*/
void Event::setType( Type t )
{
typ = t;
}
/*!
Sets the start date and time of the first or only occurance of this event
to the date and time \a d. \a d should be in local time.
*/
void Event::setStart( const QDateTime &d )
{
startUTC = TimeConversion::toUTC( d );
}
/*!
\internal
*/
void Event::setStart( time_t time )
{
startUTC = time;
}
/*!
Sets the end date and time of the first or only occurance of this event
to the date and time \a d. \a d should be in local time.
*/
void Event::setEnd( const QDateTime &d )
{
endUTC = TimeConversion::toUTC( d );
}
/*!
\internal
*/
void Event::setEnd( time_t time )
{
endUTC = time;
}
/*!
\internal
*/
void Event::setTimeZone( const QString &z )
{
tz = z;
}
/*!
\internal
*/
void Event::setAlarm( bool b, int minutes, SoundTypeChoice s )
{
hAlarm = b;
aMinutes = minutes;
aSound = s;
}
/*!
\internal
*/
void Event::setRepeat( bool b, const RepeatPattern &p )
{
hRepeat = b;
pattern = p;
}
/*!
Sets the notes for the event to \a n.
*/
void Event::setNotes( const QString &n )
{
note = n;
}
/*!
Returns the description of the event.
*/
const QString &Event::description() const
{
return descript;
}
/*!
Returns the location of the event.
*/
const QString &Event::location() const
{
return locat;
}
// QString Event::category() const
// {
// return categ;
// }
/*!
\internal
*/
Event::Type Event::type() const
{
return typ;
}
/*
QDateTime Event::start() const {
return start( TRUE );
}
*/
/*!
\internal
*/
QDateTime Event::start( bool actual ) const
{
QDateTime dt = TimeConversion::fromUTC( startUTC );
if ( actual && typ == AllDay ) {
QTime t = dt.time();
t.setHMS( 0, 0, 0 );
dt.setTime( t );
}
return dt;
}
/*
QDateTime Event::end() const {
return end( TRUE );
}
*/
/*!
\internal
*/
QDateTime Event::end( bool actual ) const
{
QDateTime dt = TimeConversion::fromUTC( endUTC );
if ( actual && typ == AllDay ) {
dt.setTime( QTime(23,59,59) );
}
return dt;
}
/*!
\internal
*/
const QString &Event::timeZone() const
{
return tz;
}
/*!
\internal
*/
bool Event::hasAlarm() const
{
return hAlarm;
}
/*!
\internal
*/
int Event::alarmTime() const
{
return aMinutes;
}
/*!
Returns the sound type for the alarm of this event.
*/
Event::SoundTypeChoice Event::alarmSound() const
{
return aSound;
}
/*!
\internal
*/
bool Event::hasRepeat() const
{
return doRepeat();
}
/*!
\internal
*/
const Event::RepeatPattern &Event::repeatPattern() const
{
return pattern;
}
/*!
\internal
*/
Event::RepeatPattern &Event::repeatPattern()
{
return pattern;
}
/*!
Returns the notes for the event.
*/
const QString &Event::notes() const
{
return note;
}
/*!
\internal
*/
bool Event::operator==( const Event &e ) const
{
if ( uid() && e.uid() == uid() )
return TRUE;
return ( e.descript == descript &&
e.locat == locat &&
e.categ == categ &&
e.typ == typ &&
e.startUTC == startUTC &&
e.endUTC == endUTC &&
e.tz == tz &&
e.hAlarm == hAlarm &&
e.aMinutes == aMinutes &&
e.aSound == aSound &&
e.hRepeat == hRepeat &&
e.pattern == pattern &&
e.note == note );
}
/*!
\internal
Appends the contact information to \a buf.
*/
void Event::save( QString& buf )
{
buf += " description=\"" + Qtopia::escapeString(descript) + "\"";
if ( !locat.isEmpty() )
buf += " location=\"" + Qtopia::escapeString(locat) + "\"";
// save the categoies differently....
QString strCats = idsToString( categories() );
buf += " categories=\"" + Qtopia::escapeString(strCats) + "\"";
buf += " uid=\"" + QString::number( uid() ) + "\"";
if ( (Type)typ != Normal )
buf += " type=\"AllDay\"";
if ( hAlarm ) {
buf += " alarm=\"" + QString::number( aMinutes ) + "\" sound=\"";
if ( aSound == Event::Loud )
buf += "loud";
else
buf += "silent";
buf += "\"";
}
if ( hRepeat )
write( buf, pattern );
buf += " start=\""
+ QString::number( startUTC )
+ "\"";
buf += " end=\""
+ QString::number( endUTC )
+ "\"";
if ( !note.isEmpty() )
buf += " note=\"" + Qtopia::escapeString( note ) + "\"";
buf += customToXml();
}
/*!
\internal
*/
bool Event::RepeatPattern::operator==( const Event::RepeatPattern &right ) const
{
// *sigh*
return ( type == right.type
&& frequency == right.frequency
&& position == right.position
&& days == right.days
&& hasEndDate == right.hasEndDate
&& endDateUTC == right.endDateUTC
&& createTime == right.createTime );
}
/*!
\class EffectiveEvent
\brief The EffectiveEvent class the data for a single occurance of an event.
This class describes the event for a single occurance of it. For example if
an Event occurs every week, the effective event might represent the third
occurance of this Event.
\ingroup qtopiaemb
\ingroup qtopiadesktop
\warning This class will be phased out in Qtopia 3.x
*/
/*!
\enum EffectiveEvent::Position
\internal
*/
/*!
\fn EffectiveEvent &EffectiveEvent::operator=(const EffectiveEvent &)
\internal
*/
class EffectiveEventPrivate
{
public:
//currently the existence of the d pointer means multi-day repeating,
//msut be changed if we use the d pointer for anything else.
QDate startDate;
QDate endDate;
};
/*!
\internal
*/
EffectiveEvent::EffectiveEvent()
{
mDate = QDate::currentDate();
mStart = mEnd = QTime::currentTime();
d = 0;
}
/*!
\internal
*/
EffectiveEvent::EffectiveEvent( const Event &e, const QDate &date, Position pos )
{
mEvent = e;
mDate = date;
if ( pos & Start )
mStart = e.start( TRUE ).time();
else
mStart = QTime( 0, 0, 0 );
if ( pos & End )
mEnd = e.end( TRUE ).time();
else
mEnd = QTime( 23, 59, 59 );
d = 0;
}
/*!
\internal
*/
EffectiveEvent::~EffectiveEvent()
{
delete d;
}
/*!
\internal
*/
EffectiveEvent::EffectiveEvent( const EffectiveEvent &e )
{
d = 0;
*this = e;
}
EffectiveEvent& EffectiveEvent::operator=( const EffectiveEvent & e )
{
if ( &e == this )
return *this;
delete d;
if ( e.d ) {
d = new EffectiveEventPrivate;
d->startDate = e.d->startDate;
d->endDate = e.d->endDate;
} else {
d = 0;
}
mEvent = e.mEvent;
mDate = e.mDate;
mStart = e.mStart;
mEnd = e.mEnd;
return *this;
}
// QString EffectiveEvent::category() const
// {
// return mEvent.category();
// }
/*!
Returns the description of the event for this effective event.
*/
const QString &EffectiveEvent::description( ) const
{
return mEvent.description();
}
/*!
\internal
*/
const QString &EffectiveEvent::location( ) const
{
return mEvent.location();
}
/*!
\internal
*/
const QString &EffectiveEvent::notes() const
{
return mEvent.notes();
}
/*!
Returns the event associated with this effective event.
*/
const Event &EffectiveEvent::event() const
{
return mEvent;
}
/*!
\internal
*/
const QTime &EffectiveEvent::end() const
{
return mEnd;
}
/*!
\internal
*/
const QTime &EffectiveEvent::start() const
{
return mStart;
}
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
index b2180ba..a47bf6c 100644
--- a/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/zkbnames.cpp
@@ -1,446 +1,452 @@
#include <qmap.h>
#include "zkbnames.h"
QString Null_String((const char*) 0);
// Implementation of KeyNames
-static struct {
+struct Key_Names_t {
int key;
char *name;
-} Key_Names[] = {
+};
+
+static const Key_Names_t Key_Names[] = {
{ 32, "Space" },
{ 39, "Apostrophe" },
{ 44, "Comma" },
{ 46, "Period" },
{ 47, "Slash" },
{ 65, "A" },
{ 66, "B" },
{ 67, "C" },
{ 68, "D" },
{ 69, "E" },
{ 70, "F" },
{ 71, "G" },
{ 72, "H" },
{ 73, "I" },
{ 74, "J" },
{ 75, "K" },
{ 76, "L" },
{ 77, "M" },
{ 78, "N" },
{ 79, "O" },
{ 80, "P" },
{ 81, "Q" },
{ 82, "R" },
{ 83, "S" },
{ 84, "T" },
{ 85, "U" },
{ 86, "V" },
{ 87, "W" },
{ 88, "X" },
{ 89, "Y" },
{ 90, "Z" },
{ 4096, "Cancel" },
{ 4097, "Tab" },
{ 4099, "Backspace" },
{ 4100, "Enter" },
{ 4114, "Left" },
{ 4115, "Up" },
{ 4116, "Right" },
{ 4117, "Down" },
{ 4128, "Left Shift" },
{ 4130, "Right Shift" },
{ 4152, "Calendar" },
{ 4153, "Addressbook" },
{ 4154, "Menu" },
{ 4155, "Home" },
{ 4156, "Mail" },
{ 4165, "Fn" },
{ 4173, "Middle" },
{ 4176, "OK" },
{ 4177, "Off" },
{ 4178, "Light" },
{ 0, 0 }
};
static QMap<QString, int> kn_map;
static QMap<int, QString> kn_rmap;
void init_kn_maps() {
int i = 0;
while (Key_Names[i].name != 0) {
int key = Key_Names[i].key;
QString name(Key_Names[i].name);
kn_map.insert(name, key);
kn_rmap.insert(key, name);
i++;
}
}
int KeyNames::find(const QString& key) {
if (kn_map.isEmpty()) {
init_kn_maps();
}
QMap<QString, int>::Iterator it = kn_map.find(key);
if (it == kn_map.end()) {
return -1;
} else {
return it.data();
}
}
const QString& KeyNames::find(int k) {
if (kn_map.isEmpty()) {
init_kn_maps();
}
QMap<int, QString>::Iterator it = kn_rmap.find(k);
if (it == kn_rmap.end()) {
return Null_String;
} else {
return it.data();
}
}
// Implementation of ModifierNames
-struct {
+struct Modifier_Names_t {
int value;
char* name;
-} Modifier_Names[] = {
+};
+
+static const Modifier_Names_t Modifier_Names[] = {
{ 8, "Shift" },
{ 16, "Control" },
{ 32, "Alt" },
{ 0x4000, "Keypad" },
{ 0, 0 }
};
static QMap<QString, int> mn_map;
static QMap<int, QString> mn_rmap;
void init_mn_maps() {
int i = 0;
while (Modifier_Names[i].name != 0) {
int value = Modifier_Names[i].value;
QString name(Modifier_Names[i].name);
mn_map.insert(name, value);
mn_rmap.insert(value, name);
i++;
}
}
int ModifierNames::find(const QString& key) {
if (mn_map.isEmpty()) {
init_mn_maps();
}
QMap<QString, int>::Iterator it = mn_map.find(key);
if (it == mn_map.end()) {
return -1;
} else {
return it.data();
}
}
const QString& ModifierNames::find(int k) {
if (mn_map.isEmpty()) {
init_mn_maps();
}
QMap<int, QString>::Iterator it = mn_rmap.find(k);
if (it == mn_rmap.end()) {
return Null_String;
} else {
return it.data();
}
}
// Implementation of KeycodeNames
-struct {
+struct Keycode_Names_t {
char* name;
int keycode;
-} Keycode_Names[] = {
+};
+
+static const Keycode_Names_t Keycode_Names[] = {
{ "Escape", 0x1000 },
{ "Tab", 0x1001 },
{ "Backtab", 0x1002 },
{ "Backspace", 0x1003 },
{ "BackSpace", 0x1003 },
{ "Return", 0x1004 },
{ "Enter", 0x1005 },
{ "Insert", 0x1006 },
{ "Delete", 0x1007 },
{ "Pause", 0x1008 },
{ "Print", 0x1009 },
{ "SysReq", 0x100a },
{ "Home", 0x1010 },
{ "End", 0x1011 },
{ "Left", 0x1012 },
{ "Up", 0x1013 },
{ "Right", 0x1014 },
{ "Down", 0x1015 },
{ "Prior", 0x1016 },
{ "PageUp", 0x1016 },
{ "Next", 0x1017 },
{ "PageDown", 0x1017 },
{ "Shift", 0x1020 },
{ "Control", 0x1021 },
{ "Meta", 0x1022 },
{ "Alt", 0x1023 },
{ "CapsLock", 0x1024 },
{ "NumLock", 0x1025 },
{ "ScrollLock", 0x1026 },
{ "F1", 0x1030 },
{ "F2", 0x1031 },
{ "F3", 0x1032 },
{ "F4", 0x1033 },
{ "F5", 0x1034 },
{ "F6", 0x1035 },
{ "F7", 0x1036 },
{ "F8", 0x1037 },
{ "F9", 0x1038 },
{ "F10", 0x1039 },
{ "F11", 0x103a },
{ "F12", 0x103b },
{ "F13", 0x103c },
{ "F14", 0x103d },
{ "F15", 0x103e },
{ "F16", 0x103f },
{ "F17", 0x1040 },
{ "F18", 0x1041 },
{ "F19", 0x1042 },
{ "F20", 0x1043 },
{ "F21", 0x1044 },
{ "F22", 0x1045 },
{ "F23", 0x1046 },
{ "F24", 0x1047 },
{ "F25", 0x1048 },
{ "F26", 0x1049 },
{ "F27", 0x104a },
{ "F28", 0x104b },
{ "F29", 0x104c },
{ "F30", 0x104d },
{ "F31", 0x104e },
{ "F32", 0x104f },
{ "F33", 0x1050 },
{ "F34", 0x1051 },
{ "F35", 0x1052 },
{ "Super_L", 0x1053 },
{ "Super_R", 0x1054 },
{ "Menu", 0x1055 },
{ "Hyper_L", 0x1056 },
{ "Hyper_R", 0x1057 },
{ "Help", 0x1058 },
{ "Space", 0x20 },
{ "Any", 0x20 },
{ "Exclam", 0x21 },
{ "QuoteDbl", 0x22 },
{ "NumberSign", 0x23 },
{ "Dollar", 0x24 },
{ "Percent", 0x25 },
{ "Ampersand", 0x26 },
{ "Apostrophe", 0x27 },
{ "ParenLeft", 0x28 },
{ "ParenRight", 0x29 },
{ "Asterisk", 0x2a },
{ "Plus", 0x2b },
{ "Comma", 0x2c },
{ "Minus", 0x2d },
{ "Period", 0x2e },
{ "Slash", 0x2f },
{ "0", 0x30 },
{ "1", 0x31 },
{ "2", 0x32 },
{ "3", 0x33 },
{ "4", 0x34 },
{ "5", 0x35 },
{ "6", 0x36 },
{ "7", 0x37 },
{ "8", 0x38 },
{ "9", 0x39 },
{ "Colon", 0x3a },
{ "Semicolon", 0x3b },
{ "Less", 0x3c },
{ "Equal", 0x3d },
{ "Greater", 0x3e },
{ "Question", 0x3f },
{ "At", 0x40 },
{ "A", 0x41 },
{ "B", 0x42 },
{ "C", 0x43 },
{ "D", 0x44 },
{ "E", 0x45 },
{ "F", 0x46 },
{ "G", 0x47 },
{ "H", 0x48 },
{ "I", 0x49 },
{ "J", 0x4a },
{ "K", 0x4b },
{ "L", 0x4c },
{ "M", 0x4d },
{ "N", 0x4e },
{ "O", 0x4f },
{ "P", 0x50 },
{ "Q", 0x51 },
{ "R", 0x52 },
{ "S", 0x53 },
{ "T", 0x54 },
{ "U", 0x55 },
{ "V", 0x56 },
{ "W", 0x57 },
{ "X", 0x58 },
{ "Y", 0x59 },
{ "Z", 0x5a },
{ "BracketLeft", 0x5b },
{ "Backslash", 0x5c },
{ "BracketRight", 0x5d },
{ "AsciiCircum", 0x5e },
{ "Underscore", 0x5f },
{ "QuoteLeft", 0x60 },
{ "BraceLeft", 0x7b },
{ "Bar", 0x7c },
{ "BraceRight", 0x7d },
{ "AsciiTilde", 0x7e },
{ "nobreakspace", 0x0a0 },
{ "exclamdown", 0x0a1 },
{ "cent", 0x0a2 },
{ "sterling", 0x0a3 },
{ "currency", 0x0a4 },
{ "yen", 0x0a5 },
{ "brokenbar", 0x0a6 },
{ "section", 0x0a7 },
{ "diaeresis", 0x0a8 },
{ "copyright", 0x0a9 },
{ "ordfeminine", 0x0aa },
{ "guillemotleft", 0x0ab },
{ "notsign", 0x0ac },
{ "hyphen", 0x0ad },
{ "registered", 0x0ae },
{ "macron", 0x0af },
{ "degree", 0x0b0 },
{ "plusminus", 0x0b1 },
{ "twosuperior", 0x0b2 },
{ "threesuperior", 0x0b3 },
{ "acute", 0x0b4 },
{ "mu", 0x0b5 },
{ "paragraph", 0x0b6 },
{ "periodcentered", 0x0b7 },
{ "cedilla", 0x0b8 },
{ "onesuperior", 0x0b9 },
{ "masculine", 0x0ba },
{ "guillemotright", 0x0bb },
{ "onequarter", 0x0bc },
{ "onehalf", 0x0bd },
{ "threequarters", 0x0be },
{ "questiondown", 0x0bf },
{ "Agrave", 0x0c0 },
{ "Aacute", 0x0c1 },
{ "Acircumflex", 0x0c2 },
{ "Atilde", 0x0c3 },
{ "Adiaeresis", 0x0c4 },
{ "Aring", 0x0c5 },
{ "AE", 0x0c6 },
{ "Ccedilla", 0x0c7 },
{ "Egrave", 0x0c8 },
{ "Eacute", 0x0c9 },
{ "Ecircumflex", 0x0ca },
{ "Ediaeresis", 0x0cb },
{ "Igrave", 0x0cc },
{ "Iacute", 0x0cd },
{ "Icircumflex", 0x0ce },
{ "Idiaeresis", 0x0cf },
{ "ETH", 0x0d0 },
{ "Ntilde", 0x0d1 },
{ "Ograve", 0x0d2 },
{ "Oacute", 0x0d3 },
{ "Ocircumflex", 0x0d4 },
{ "Otilde", 0x0d5 },
{ "Odiaeresis", 0x0d6 },
{ "multiply", 0x0d7 },
{ "Ooblique", 0x0d8 },
{ "Ugrave", 0x0d9 },
{ "Uacute", 0x0da },
{ "Ucircumflex", 0x0db },
{ "Udiaeresis", 0x0dc },
{ "Yacute", 0x0dd },
{ "THORN", 0x0de },
{ "ssharp", 0x0df },
{ "agrave", 0x0e0 },
{ "aacute", 0x0e1 },
{ "acircumflex", 0x0e2 },
{ "atilde", 0x0e3 },
{ "adiaeresis", 0x0e4 },
{ "aring", 0x0e5 },
{ "ae", 0x0e6 },
{ "ccedilla", 0x0e7 },
{ "egrave", 0x0e8 },
{ "eacute", 0x0e9 },
{ "ecircumflex", 0x0ea },
{ "ediaeresis", 0x0eb },
{ "igrave", 0x0ec },
{ "iacute", 0x0ed },
{ "icircumflex", 0x0ee },
{ "idiaeresis", 0x0ef },
{ "eth", 0x0f0 },
{ "ntilde", 0x0f1 },
{ "ograve", 0x0f2 },
{ "oacute", 0x0f3 },
{ "ocircumflex", 0x0f4 },
{ "otilde", 0x0f5 },
{ "odiaeresis", 0x0f6 },
{ "division", 0x0f7 },
{ "oslash", 0x0f8 },
{ "ugrave", 0x0f9 },
{ "uacute", 0x0fa },
{ "ucircumflex", 0x0fb },
{ "udiaeresis", 0x0fc },
{ "yacute", 0x0fd },
{ "thorn", 0x0fe },
{ "ydiaeresis", 0x0ff },
{ "unknown", 0xffff },
{ 0, 0}
};
static QMap<QString, int> kcn_map;
static QMap<int, QString> kcn_rmap;
void init_kcn_maps() {
int i = 0;
while (Keycode_Names[i].name != 0) {
int keycode = Keycode_Names[i].keycode;
QString name(Keycode_Names[i].name);
kcn_map.insert(name, keycode);
kcn_rmap.insert(keycode, name);
i++;
}
}
int KeycodeNames::find(const QString& key) {
if (kcn_map.isEmpty()) {
init_kcn_maps();
}
QMap<QString, int>::Iterator it = kcn_map.find(key);
if (it == kcn_map.end()) {
return -1;
} else {
return it.data();
}
}
const QString& KeycodeNames::find(int k) {
if (kcn_map.isEmpty()) {
init_kcn_maps();
}
QMap<int, QString>::Iterator it = kcn_rmap.find(k);
if (it == kcn_rmap.end()) {
return Null_String;
} else {
return it.data();
}
}
diff --git a/noncore/games/qasteroids/view.cpp b/noncore/games/qasteroids/view.cpp
index 352c63b..3a4d410 100644
--- a/noncore/games/qasteroids/view.cpp
+++ b/noncore/games/qasteroids/view.cpp
@@ -1,576 +1,577 @@
/**********************************************************************
** 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.
**
**********************************************************************//*
* KAsteroids - Copyright (c) Martin R. Jones 1997
*
* Part of the KDE project
*/
#include "view.h"
#include <qpe/resource.h>
#include <stdlib.h>
#include <math.h>
#define IMG_BACKGROUND "qasteroids/bg.png"
#define REFRESH_DELAY 33
#define SHIP_SPEED 0.3
#define MISSILE_SPEED 10.0
#define SHIP_STEPS 64
#define ROTATE_RATE 2
#define SHIELD_ON_COST 1
#define SHIELD_HIT_COST 30
#define BRAKE_ON_COST 4
#define MAX_ROCK_SPEED 2.5
#define MAX_POWERUP_SPEED 1.5
#define MAX_SHIP_SPEED 8
#define MAX_BRAKES 5
#define MAX_SHIELDS 5
#define MAX_FIREPOWER 5
#define TEXT_SPEED 4
#define PI_X_2 6.283185307
#ifndef M_PI
#define M_PI 3.141592654
#endif
-struct
+struct kas_animations_t
{
int id;
const char *path;
int frames;
-}
-kas_animations [] =
+};
+
+static const kas_animations_t kas_animations [] =
{
// { ID_ROCK_LARGE, "rock1/rock1\%1.png", 32 },
{ ID_ROCK_MEDIUM, "rock2/rock2\%1.png", 32 },
{ ID_ROCK_SMALL, "rock3/rock3\%1.png", 32 },
{ ID_SHIP, "ship/ship\%1.png", 32 },
{ ID_MISSILE, "missile/missile.png", 0 },
{ ID_BIT, "bits/bits\%1.png", 16 },
{ ID_EXHAUST, "exhaust/exhaust.png", 0 },
{ ID_ENERGY_POWERUP, "powerups/energy.png", 0 },
// { ID_TELEPORT_POWERUP, "powerups/teleport%1.png", 12 },
{ ID_BRAKE_POWERUP, "powerups/brake.png", 0 },
{ ID_SHIELD_POWERUP, "powerups/shield.png", 0 },
{ ID_SHOOT_POWERUP, "powerups/shoot.png", 0 },
{ ID_SHIELD, "shield/shield\%1.png", 6 },
{ 0, 0, 0 }
};
KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name )
: QWidget( parent, name ),
field(200, 200),
view(&field,this)
{
view.setVScrollBarMode( QScrollView::AlwaysOff );
view.setHScrollBarMode( QScrollView::AlwaysOff );
rocks.setAutoDelete( TRUE );
missiles.setAutoDelete( TRUE );
bits.setAutoDelete( TRUE );
powerups.setAutoDelete( TRUE );
exhaust.setAutoDelete( TRUE );
QPixmap pm( Resource::loadPixmap(IMG_BACKGROUND) );
field.setBackgroundPixmap( pm );
textSprite = new QCanvasText( &field );
QFont font( "helvetica", 14 );
textSprite->setFont( font );
shield = 0;
shieldOn = FALSE;
refreshRate = REFRESH_DELAY;
readSprites();
shieldTimer = new QTimer( this );
connect( shieldTimer, SIGNAL(timeout()), this, SLOT(hideShield()) );
mTimerId = -1;
shipPower = MAX_POWER_LEVEL;
vitalsChanged = TRUE;
can_destroy_powerups = FALSE;
mPaused = TRUE;
}
// - - -
KAsteroidsView::~KAsteroidsView()
{
}
// - - -
void KAsteroidsView::reset()
{
rocks.clear();
missiles.clear();
bits.clear();
powerups.clear();
exhaust.clear();
shotsFired = 0;
shotsHit = 0;
rockSpeed = 1.0;
powerupSpeed = 1.0;
mFrameNum = 0;
mPaused = FALSE;
ship->hide();
shield->hide();
/*
if ( mTimerId >= 0 ) {
killTimer( mTimerId );
mTimerId = -1;
}
*/
}
// - --
void KAsteroidsView::newGame()
{
if ( shieldOn )
{
shield->hide();
shieldOn = FALSE;
}
reset();
if ( mTimerId < 0 )
mTimerId = startTimer( REFRESH_DELAY );
emit updateVitals();
}
// - - -
void KAsteroidsView::endGame()
{
}
void KAsteroidsView::pause( bool p )
{
if ( !mPaused && p ) {
if ( mTimerId >= 0 ) {
killTimer( mTimerId );
mTimerId = -1;
}
} else if ( mPaused && !p )
mTimerId = startTimer( REFRESH_DELAY );
mPaused = p;
}
// - - -
void KAsteroidsView::newShip()
{
ship->move( field.width()/2, field.height()/2, 0 );
shield->move( field.width()/2, field.height()/2, 0 );
ship->setVelocity( 0.0, 0.0 );
shipDx = 0;
shipDy = 0;
shipAngle = 0;
rotateL = FALSE;
rotateR = FALSE;
thrustShip = FALSE;
shootShip = FALSE;
brakeShip = FALSE;
teleportShip = FALSE;
shieldOn = TRUE;
shootDelay = 0;
shipPower = MAX_POWER_LEVEL;
rotateRate = ROTATE_RATE;
rotateSlow = 0;
mBrakeCount = 0;
mTeleportCount = 0;
mShootCount = 0;
ship->show();
shield->show();
mShieldCount = 1; // just in case the ship appears on a rock.
shieldTimer->start( 1000, TRUE );
}
void KAsteroidsView::setShield( bool s )
{
if ( shieldTimer->isActive() && !s ) {
shieldTimer->stop();
hideShield();
} else {
shieldOn = s && mShieldCount;
}
}
void KAsteroidsView::brake( bool b )
{
if ( mBrakeCount )
{
if ( brakeShip && !b )
{
rotateL = FALSE;
rotateR = FALSE;
thrustShip = FALSE;
rotateRate = ROTATE_RATE;
}
brakeShip = b;
}
}
// - - -
void KAsteroidsView::readSprites()
{
QString sprites_prefix = Resource::findPixmap( IMG_BACKGROUND );
int sep = sprites_prefix.findRev( "/" );
sprites_prefix.truncate( sep );
int i = 0;
while ( kas_animations[i].id )
{
animation.insert( kas_animations[i].id,
new QCanvasPixmapArray( sprites_prefix + "/" + kas_animations[i].path,
kas_animations[i].frames ) );
i++;
}
ship = new QCanvasSprite( animation[ID_SHIP], &field );
ship->hide();
shield = new KShield( animation[ID_SHIELD], &field );
shield->hide();
}
// - - -
void KAsteroidsView::addRocks( int num )
{
for ( int i = 0; i < num; i++ )
{
KRock *rock = new KRock( animation[ID_ROCK_MEDIUM], &field,
ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
double dx = (2.0 - randDouble()*4.0) * rockSpeed;
double dy = (2.0 - randDouble()*4.0) * rockSpeed;
rock->setVelocity( dx, dy );
rock->setFrame( randInt( rock->frameCount() ) );
if ( dx > 0 )
{
if ( dy > 0 )
rock->move( 5, 5, 0 );
else
rock->move( 5, field.height() - 25, 0 );
}
else
{
if ( dy > 0 )
rock->move( field.width() - 25, 5, 0 );
else
rock->move( field.width() - 25, field.height() - 25, 0 );
}
rock->show( );
rocks.append( rock );
}
}
// - - -
void KAsteroidsView::showText( const QString &text, const QColor &color, bool scroll )
{
textSprite->setTextFlags( AlignLeft | AlignVCenter );
textSprite->setText( text );
textSprite->setColor( color );
if ( scroll ) {
textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
-textSprite->boundingRect().height() );
textDy = TEXT_SPEED;
} else {
textSprite->move( (field.width()-textSprite->boundingRect().width()) / 2,
(field.height()-textSprite->boundingRect().height()) / 2 );
textDy = 0;
}
textSprite->show();
}
// - - -
void KAsteroidsView::hideText()
{
textDy = -TEXT_SPEED;
}
// - - -
void KAsteroidsView::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
field.resize(width()-4, height()-4);
view.resize(width(),height());
}
// - - -
void KAsteroidsView::timerEvent( QTimerEvent * )
{
field.advance();
QCanvasSprite *rock;
// move rocks forward
for ( rock = rocks.first(); rock; rock = rocks.next() ) {
((KRock *)rock)->nextFrame();
wrapSprite( rock );
}
wrapSprite( ship );
// check for missile collision with rocks.
processMissiles();
// these are generated when a ship explodes
for ( KBit *bit = bits.first(); bit; bit = bits.next() )
{
if ( bit->expired() )
{
bits.removeRef( bit );
}
else
{
bit->growOlder();
bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() );
}
}
for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() )
exhaust.removeRef( e );
// move / rotate ship.
// check for collision with a rock.
processShip();
// move powerups and check for collision with player and missiles
processPowerups();
if ( textSprite->visible() )
{
if ( textDy < 0 &&
textSprite->boundingRect().y() <= -textSprite->boundingRect().height() ) {
textSprite->hide();
} else {
textSprite->moveBy( 0, textDy );
}
if ( textSprite->boundingRect().y() > (field.height()-textSprite->boundingRect().height())/2 )
textDy = 0;
}
if ( vitalsChanged && !(mFrameNum % 10) ) {
emit updateVitals();
vitalsChanged = FALSE;
}
mFrameNum++;
}
void KAsteroidsView::wrapSprite( QCanvasItem *s )
{
int x = int(s->x() + s->boundingRect().width() / 2);
int y = int(s->y() + s->boundingRect().height() / 2);
if ( x > field.width() )
s->move( s->x() - field.width(), s->y() );
else if ( x < 0 )
s->move( field.width() + s->x(), s->y() );
if ( y > field.height() )
s->move( s->x(), s->y() - field.height() );
else if ( y < 0 )
s->move( s->x(), field.height() + s->y() );
}
// - - -
void KAsteroidsView::rockHit( QCanvasItem *hit )
{
KPowerup *nPup = 0;
int rnd = static_cast<int>(randDouble()*30.0) % 30;
switch( rnd )
{
case 4:
case 5:
nPup = new KPowerup( animation[ID_ENERGY_POWERUP], &field,
ID_ENERGY_POWERUP );
break;
case 10:
// nPup = new KPowerup( animation[ID_TELEPORT_POWERUP], &field,
// ID_TELEPORT_POWERUP );
break;
case 15:
nPup = new KPowerup( animation[ID_BRAKE_POWERUP], &field,
ID_BRAKE_POWERUP );
break;
case 20:
nPup = new KPowerup( animation[ID_SHIELD_POWERUP], &field,
ID_SHIELD_POWERUP );
break;
case 24:
case 25:
nPup = new KPowerup( animation[ID_SHOOT_POWERUP], &field,
ID_SHOOT_POWERUP );
break;
}
if ( nPup )
{
double r = 0.5 - randDouble();
nPup->move( hit->x(), hit->y(), 0 );
nPup->setVelocity( hit->xVelocity() + r, hit->yVelocity() + r );
nPup->show( );
powerups.append( nPup );
}
if ( hit->rtti() == ID_ROCK_LARGE || hit->rtti() == ID_ROCK_MEDIUM )
{
// break into smaller rocks
double addx[4] = { 1.0, 1.0, -1.0, -1.0 };
double addy[4] = { -1.0, 1.0, -1.0, 1.0 };
double dx = hit->xVelocity();
double dy = hit->yVelocity();
double maxRockSpeed = MAX_ROCK_SPEED * rockSpeed;
if ( dx > maxRockSpeed )
dx = maxRockSpeed;
else if ( dx < -maxRockSpeed )
dx = -maxRockSpeed;
if ( dy > maxRockSpeed )
dy = maxRockSpeed;
else if ( dy < -maxRockSpeed )
dy = -maxRockSpeed;
QCanvasSprite *nrock;
for ( int i = 0; i < 4; i++ )
{
double r = rockSpeed/2 - randDouble()*rockSpeed;
if ( hit->rtti() == ID_ROCK_LARGE )
{
nrock = new KRock( animation[ID_ROCK_MEDIUM], &field,
ID_ROCK_MEDIUM, randInt(2), randInt(2) ? -1 : 1 );
emit rockHit( 0 );
}
else
{
nrock = new KRock( animation[ID_ROCK_SMALL], &field,
ID_ROCK_SMALL, randInt(2), randInt(2) ? -1 : 1 );
emit rockHit( 1 );
}
nrock->move( hit->x(), hit->y(), 0 );
nrock->setVelocity( dx+addx[i]*rockSpeed+r, dy+addy[i]*rockSpeed+r );
nrock->setFrame( randInt( nrock->frameCount() ) );
nrock->show( );
rocks.append( nrock );
}
}
else if ( hit->rtti() == ID_ROCK_SMALL )
emit rockHit( 2 );
rocks.removeRef( (QCanvasSprite *)hit );
if ( rocks.count() == 0 )
emit rocksRemoved();
}
void KAsteroidsView::reducePower( int val )
{
shipPower -= val;
if ( shipPower <= 0 )
{
shipPower = 0;
thrustShip = FALSE;
if ( shieldOn )
{
shieldOn = FALSE;
shield->hide();
}
}
vitalsChanged = TRUE;
}
void KAsteroidsView::addExhaust( double x, double y, double dx,
double dy, int count )
{
for ( int i = 0; i < count; i++ )
{
KExhaust *e = new KExhaust( animation[ID_EXHAUST], &field );
e->move( x + 2 - randDouble()*4, y + 2 - randDouble()*4 );
e->setVelocity( dx, dy );
e->show( );
exhaust.append( e );
}
}
void KAsteroidsView::processMissiles()
{
KMissile *missile;
// if a missile has hit a rock, remove missile and break rock into smaller
// rocks or remove completely.
QPtrListIterator<KMissile> it(missiles);
for ( ; it.current(); ++it )
{
missile = it.current();
missile->growOlder();
if ( missile->expired() )
{
missiles.removeRef( missile );
continue;
}
wrapSprite( missile );
QCanvasItemList hits = missile->collisions( TRUE );
QCanvasItemList::Iterator hit;
for ( hit = hits.begin(); hit != hits.end(); ++hit )
{
if ( (*hit)->rtti() >= ID_ROCK_LARGE &&
(*hit)->rtti() <= ID_ROCK_SMALL )
{
shotsHit++;
rockHit( *hit );
missiles.removeRef( missile );
break;
}
}
}
}
// - - -
void KAsteroidsView::processShip()
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h
index 1eb2499..757e6b3 100644
--- a/noncore/games/solitaire/cardpile.h
+++ b/noncore/games/solitaire/cardpile.h
@@ -1,115 +1,117 @@
/**********************************************************************
** 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.
**
**********************************************************************/
#ifndef CARD_PILE_H
#define CARD_PILE_H
+#include "card.h"
+
#include <qpoint.h>
#include <qlist.h>
enum ePileStackingType {
pileCascades = 0, pileStacks, pileCascadesOrStacks
};
enum ePileFaceingType {
pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown
};
class Card;
class Config;
class CardPile : public QList<Card>
{
public:
CardPile(int x, int y);
virtual ~CardPile() { }
int getX() { return pileX; }
int getY() { return pileY; }
int getNextX() { return pileNextX; }
int getNextY() { return pileNextY; }
int getWidth() { return pileWidth; }
int getHeight() { return pileHeight; }
int getOffsetDown() { return pileOffsetDown; }
int getAnzCardsInPile() {
int anz=0;
Card *card = cardOnBottom();
while (card != NULL) { anz++; card = cardInfront(card); }
return anz;
}
void setX(int x) { pileX = x; }
void setY(int y) { pileY = y; }
void setNextX(int x) { pileNextX = x; }
void setNextY(int y) { pileNextY = y; }
void setWidth(int width) { pileWidth = width; }
void setHeight(int height) { pileHeight = height; }
void setOffsetDown(int down) { pileOffsetDown = down; }
void beginDealing() { dealing = TRUE; }
void endDealing() { dealing = FALSE; }
bool isDealing() { return dealing; }
void beginPileResize() { PileResize = TRUE; }
void endPileResize() { PileResize = FALSE; }
bool isPileResize() { return PileResize; }
int distanceFromPile(int x, int y);
int distanceFromNextPos(int x, int y);
Card *cardOnTop() { return getLast(); }
Card *cardOnBottom() { return getFirst(); }
Card *cardInfront(Card *c);
bool kingOnTop();
bool addCardToTop(Card *c);
bool addCardToBottom(Card *c);
bool removeCard(Card *c);
virtual void cardAddedToTop(Card *) { }
virtual void cardAddedToBottom(Card *) { }
virtual void cardRemoved(Card *) { }
virtual bool isAllowedOnTop(Card *) { return FALSE; }
virtual bool isAllowedOnBottom(Card *) { return FALSE; }
virtual bool isAllowedToBeMoved(Card *) { return FALSE; }
virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); }
virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); }
void writeConfig( Config& cfg, QString name );
protected:
int pileX, pileY;
int pileNextX, pileNextY;
int pileWidth, pileHeight;
int pileCenterX, pileCenterY;
int pileRadius;
int pileOffsetDown;
private:
bool dealing;
bool PileResize;
};
#endif