summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/phonenumber.cpp2
-rw-r--r--kalarmd/simplealarmdaemonimpl.cpp8
2 files changed, 5 insertions, 5 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 897c56d..12b9b09 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,374 +1,374 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <kapplication.h>
#include <klocale.h>
#include "phonenumber.h"
using namespace KABC;
PhoneNumber::PhoneNumber() :
mType( Home )
{
init();
}
PhoneNumber::PhoneNumber( const QString &number, int type ) :
mType( type ), mNumber( number )
{
init();
}
PhoneNumber::~PhoneNumber()
{
}
void PhoneNumber::init()
{
mId = KApplication::randomString( 8 );
}
bool PhoneNumber::operator==( const PhoneNumber &p ) const
{
if ( mNumber != p.mNumber ) return false;
if ( mType != p.mType ) return false;
return true;
}
bool PhoneNumber::operator!=( const PhoneNumber &p ) const
{
return !( p == *this );
}
void PhoneNumber::makeCompat()
{
mType = getCompatType( mType );
}
int PhoneNumber::getCompatType( int type )
{
if ((type & Cell) == Cell) {
if ((type & Work) == Work)
return Car;
return Cell;
}
if ((type & Home) == Home) {
if ((type & Pref) == Pref)
return (Home | Pref);
if ((type & Fax) == Fax)
return (Home | Fax);
return (Home);
}
if ((type & Work) == Work) {
if ((type & Pref) == Pref)
return (Work| Pref);
if ((type & Fax) == Fax)
return (Fax |Work);
if ((type & Msg) == Msg) {
if ((type & Voice) == Voice)
return ( Msg | Voice |Work);
return ( Msg | Work);
}
return Work;
}
if ((type & Pcs) == Pcs) {
if ((type & Pref) == Pref)
return Pcs | Pref;
if ((type & Voice) == Voice)
return Pcs | Voice;
return Pcs;
}
if ((type & Car) == Car)
return Car;
if ((type & Pager) == Pager)
return Pager;
if ((type & Isdn) == Isdn)
return Isdn;
#if 0
if ((type & Video) == Video)
return Video;
#endif
if ((type & Msg) == Msg)
return Msg;
if ((type & Fax) == Fax)
return Fax;
if ((type & Pref) == Pref)
return Pref;
return Voice;
}
bool PhoneNumber::simplifyNumber()
{
QString Number;
int i;
Number = mNumber.stripWhiteSpace ();
mNumber = "";
for ( i = 0; i < Number.length(); ++i) {
if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
mNumber += Number.at(i);
}
return ( mNumber.length() > 0 );
}
// make cellphone compatible
void PhoneNumber::simplifyType()
{
if ( mType & Fax ) mType = Fax;
else if ( mType & Cell ) mType = Cell;
else if ( mType & Work ) mType = Work ;
else if ( mType & Home ) mType = Home;
else mType = Pref;
}
bool PhoneNumber::contains( const PhoneNumber &p )
{
PhoneNumber myself;
PhoneNumber other;
myself = *this;
other = p;
myself.simplifyNumber();
other.simplifyNumber();
if ( myself.number() != other.number ())
return false;
myself.simplifyType();
other.simplifyType();
if ( myself.type() == other.type())
return true;
return false;
}
void PhoneNumber::setId( const QString &id )
{
mId = id;
}
QString PhoneNumber::id() const
{
return mId;
}
void PhoneNumber::setNumber( const QString &number )
{
mNumber = number;
}
QString PhoneNumber::number() const
{
return mNumber;
}
void PhoneNumber::setType( int type )
{
mType = type;
}
int PhoneNumber::type() const
{
return mType;
}
QString PhoneNumber::typeLabel() const
{
QString label;
bool first = true;
TypeList list = typeList();
TypeList::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
if ( first )
first = false;
}
}
return label;
}
QString PhoneNumber::label() const
{
return typeLabel( type() );
}
PhoneNumber::TypeList PhoneNumber::typeList()
{
TypeList list;
list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
<< Bbs << Modem << Car << Isdn << Pcs << Pager;
return list;
}
PhoneNumber::TypeList PhoneNumber::supportedTypeList()
{
static TypeList list;
if ( list.count() == 0 )
list << (Home| Pref) << (Work| Pref) << Cell <<(Pcs|Pref)<< (Pcs|Voice)<< Home << Work << Car << Pcs <<(Work| Msg | Voice) << (Work| Msg) << (Home | Fax) << (Work| Fax) << Fax<< Pager << Isdn << Msg << Pref << Voice;
return list;
}
QStringList PhoneNumber::supportedTypeListNames()
{
static QStringList list;
if ( list.count() == 0 )
- list << i18n("Home") << i18n("Work") << i18n("Mobile") << i18n("SIP") << i18n("VoIP") <<i18n("Home2")<< i18n("Work2") << i18n("Mobile2") << i18n("SIP2") << i18n("Assistent") << i18n("Company") << i18n("Fax (Home)") << i18n("Fax (Work)") << i18n("Fax (Other)") << i18n("Pager") << i18n("ISDN") << i18n("Callback") << i18n("Primary")<< i18n("Other");
+ list << i18n("Home") << i18n("Work") << i18n("Mobile") << i18n("SiP") << i18n("VoIP") <<i18n("Home2")<< i18n("Work2") << i18n("Mobile2") << i18n("SiP2") << i18n("Assistent") << i18n("Company") << i18n("Fax (Home)") << i18n("Fax (Work)") << i18n("Fax (Other)") << i18n("Pager") << i18n("ISDN") << i18n("Callback") << i18n("Primary")<< i18n("Other");
return list;
}
int PhoneNumber::typeListIndex4Type(int type )
{
TypeList list = supportedTypeList();
int i = 0;
while ( i < list.count() ) {
if ( list [i] == type )
return i;
++i;
}
return list.count()-1;
}
QString PhoneNumber::label( int type )
{
return typeLabel( type );
}
QString PhoneNumber::typeLabel( int type )
{
if ((type & Cell) == Cell)
return i18n("Mobile");
if ((type & Home) == Home) {
if ((type & Pref) == Pref)
return i18n("Home");
if ((type & Fax) == Fax)
return i18n("Fax (Home)");
return i18n("Home2");
}
if ((type & Work) == Work) {
if ((type & Pref) == Pref)
return i18n("Work");
if ((type & Fax) == Fax)
return i18n("Fax (Work)");
if ((type & Msg) == Msg) {
if ((type & Voice) == Voice)
return i18n("Assistent");
return i18n("Company");
}
return i18n("Work2");
}
if ((type & Pcs) == Pcs) {
if ((type & Pref) == Pref)
return i18n("SiP");
if ((type & Voice) == Voice)
return i18n("VoIP");
return i18n("SiP2");
}
if ((type & Car) == Car)
return i18n("Mobile2");
if ((type & Pager) == Pager)
return i18n("Pager");
if ((type & Isdn) == Isdn)
return i18n("ISDN");
if ((type & Video) == Video)
return i18n("Video");
if ((type & Msg) == Msg)
return i18n("Callback");
if ((type & Fax) == Fax)
return i18n("Fax (Other)");
if ((type & Pref) == Pref)
return i18n("Primary");
return i18n("Other");
#if 0
QString typeString;
if ((type & Cell) == Cell)
typeString += i18n("Mobile") +" ";
if ((type & Home) == Home)
typeString += i18n("Home")+" ";
else if ((type & Work) == Work)
typeString += i18n("Work")+" ";
if ((type & Sip) == Sip)
typeString += i18n("SIP")+" ";
if ((type & Car) == Car)
typeString += i18n("Car")+" ";
if ((type & Fax) == Fax)
typeString += i18n("Fax");
else if ((type & Msg) == Msg)
typeString += i18n("Messenger");
else if ((type & Video) == Video)
typeString += i18n("Video");
else if ((type & Bbs) == Bbs)
typeString += i18n("Mailbox");
else if ((type & Modem) == Modem)
typeString += i18n("Modem");
else if ((type & Isdn) == Isdn)
typeString += i18n("ISDN");
else if ((type & Pcs) == Pcs)
typeString += i18n("PCS");
else if ((type & Pager) == Pager)
typeString += i18n("Pager");
// add the prefered flag
/*
if ((type & Pref) == Pref)
typeString += i18n("(p)");
*/
//if we still have no match, return "other"
if (typeString.isEmpty()) {
if ((type & Voice) == Voice)
return i18n("Voice");
else
return i18n("Other");
}
return typeString.stripWhiteSpace();
#endif
}
QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
{
return s << phone.mId << phone.mType << phone.mNumber;
}
QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
{
s >> phone.mId >> phone.mType >> phone.mNumber;
return s;
}
diff --git a/kalarmd/simplealarmdaemonimpl.cpp b/kalarmd/simplealarmdaemonimpl.cpp
index fe9ff5a..141a9ce 100644
--- a/kalarmd/simplealarmdaemonimpl.cpp
+++ b/kalarmd/simplealarmdaemonimpl.cpp
@@ -1,502 +1,502 @@
/*
This file is part of the KOrganizer alarm daemon.
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
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 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include "simplealarmdaemonimpl.h"
#include "alarmdialog.h"
#include <qpopupmenu.h>
#include <qapp.h>
#include <qdir.h>
#include <qfile.h>
#include <qhbox.h>
#include <qtimer.h>
#include <qfile.h>
#include <qdatetime.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qdialog.h>
#define protected public
#include <qspinbox.h>
#undef protected
#include <qtextstream.h>
#include <qtopia/qcopenvelope_qws.h>
#include <qtopia/alarmserver.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
SimpleAlarmDaemonImpl::SimpleAlarmDaemonImpl( QWidget *parent )
: QLabel( parent )
{
mAlarmDialog = new AlarmDialog( 0 );
mPopUp = new QPopupMenu( this );
mPopUp->insertItem( "What's Next?", this, SLOT ( showWN() ) );
mPopUp->insertItem( "Next Days!", this, SLOT ( showKO() ) );
mPopUp->insertSeparator();
mPopUp->insertItem( "Todo List", this, SLOT ( showTodo() ) );
mPopUp->insertSeparator();
mPopUp->insertItem( "Addresses", this, SLOT ( showAdd() ) );
mPopUp->insertSeparator();
mPopUp->insertItem( "Edit Journal", this, SLOT ( writeJournal() ) );
mPopUp->insertItem( "New Event", this, SLOT ( newEvent() ) );
mPopUp->insertItem( "New Todo", this, SLOT ( newTodo() ) );
mPopUp->insertItem( "New Mail", this, SLOT ( newMail() ) );
mPopUp->insertSeparator();
mPopUp->insertItem( "Multi Sync", this, SLOT ( ringSync() ) );
mTimerPopUp = new QPopupMenu( this );
mBeepPopUp = new QPopupMenu( this );
mSoundPopUp = new QPopupMenu( this );
mPausePopUp = new QPopupMenu( this );
mFontsizePopup = new QPopupMenu( this );
mFontsizePopup->insertItem( "10", 10 );
mFontsizePopup->insertItem( "12", 12 );
mFontsizePopup->insertItem( "14", 14 );
mFontsizePopup->insertItem( "16", 16 );
mFontsizePopup->insertItem( "18", 18 );
mFontsizePopup->insertItem( "20", 20 );
mFontsizePopup->insertItem( "22", 22 );
mFontsizePopup->insertItem( "24", 24 );
mFontsizePopup->insertItem( "26", 26 );
mFontsizePopup->insertItem( "28", 28 );
mFontsizePopup->insertItem( "30", 30 );
mFontsizePopup->insertItem( "32", 32 );
mFontsizePopup->insertItem( "36", 36 );
QPopupMenu* savePopUp = new QPopupMenu( this );
savePopUp->insertItem( "Save", 0 );
savePopUp->insertItem( "Load", 1 );
mSoundPopUp->insertItem( "Buzzer", 0 );
mSoundPopUp->insertItem( "Wav file", 1 );
mPausePopUp->insertItem( " 1 sec", 1 );
mPausePopUp->insertItem( " 2 sec", 2 );
mPausePopUp->insertItem( " 3 sec", 3 );
mPausePopUp->insertItem( " 5 sec", 5 );
mPausePopUp->insertItem( "10 sec", 10 );
+ mPausePopUp->insertItem( "15 sec", 15 );
mPausePopUp->insertItem( "30 sec", 30 );
mPausePopUp->insertItem( " 1 min", 60 );
mPausePopUp->insertItem( " 5 min", 300 );
- mPausePopUp->insertItem( "10 min", 600 );
mSuspendPopUp = new QPopupMenu( this );
mSuspendPopUp->insertItem( "Off", 0 );
mSuspendPopUp->insertItem( " 1x", 1 );
mSuspendPopUp->insertItem( " 2x", 2 );
mSuspendPopUp->insertItem( " 3x", 3 );
mSuspendPopUp->insertItem( " 5x", 5 );
mSuspendPopUp->insertItem( "10x", 10 );
mSuspendPopUp->insertItem( "20x", 20 );
mSuspendPopUp->insertItem( "30x", 30 );
mBeepPopUp->insertItem( "Config",savePopUp );
mBeepPopUp->insertItem( "Replay",mSoundPopUp );
mBeepPopUp->insertItem( "Font Size",mFontsizePopup );
mBeepPopUp->insertItem( "Auto suspend",mSuspendPopUp );
mBeepPopUp->insertItem( "Beep interval",mPausePopUp );
- mBeepPopUp->insertItem( "180", 180 );
- mBeepPopUp->insertItem( "60", 60 );
- mBeepPopUp->insertItem( "30", 30 );
+ mBeepPopUp->insertItem( "100", 100 );
+ mBeepPopUp->insertItem( "50", 50 );
+ mBeepPopUp->insertItem( "25", 25 );
mBeepPopUp->insertItem( "17", 17 );
mBeepPopUp->insertItem( "10", 10 );
mBeepPopUp->insertItem( "3", 3 );
mBeepPopUp->insertItem( "1", 1 );
mBeepPopUp->insertItem( "Off", 0 );
mBeepPopUp->insertSeparator();
mBeepPopUp->insertItem( "Simulate", 1000 );
mBeepPopUp->setCheckable( true );
mPopUp->insertSeparator();
mPopUp->insertItem( "Play beeps", mBeepPopUp );
mPopUp->insertSeparator();
mPopUp->insertItem( "Timer", mTimerPopUp );
//mPopUp->insertSeparator();
//mPopUp->insertItem( "Simulate", this, SLOT ( simulate() ) );
mPopUp->resize( mPopUp->sizeHint() );
mPlayBeeps = 60;
mBeepPopUp->setItemChecked ( mPlayBeeps, true );
connect ( mBeepPopUp, SIGNAL( activated ( int ) ), this, SLOT (slotPlayBeep( int ) ) );
connect ( mTimerPopUp, SIGNAL( activated ( int ) ), this, SLOT (confTimer( int ) ) );
connect ( mTimerPopUp, SIGNAL(aboutToShow() ), this, SLOT ( showTimer( ) ) );
connect ( mSoundPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSound( int ) ) );
connect ( mPausePopUp, SIGNAL( activated ( int ) ), this, SLOT (confPause( int ) ) );
connect ( mSuspendPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSuspend( int ) ) );
connect ( savePopUp, SIGNAL( activated ( int ) ), this, SLOT (saveSlot( int ) ) );
connect ( mFontsizePopup, SIGNAL( activated ( int ) ), this, SLOT (confFontSize( int ) ) );
mTimerTime = 0;
mCustomText = "Custom Text";
mCustomMinutes = 7;
mTimerPopupConf = 1;
fillTimerPopUp();
mPausePlay = 0;
confPause( 1 );
mSuspend = 0;
confSuspend( 0 );
if ( QApplication::desktop()->width() < 480 ) {
wavAlarm = false;
mSoundPopUp->setItemChecked ( 0, true );
}
else {
wavAlarm = true;
mSoundPopUp->setItemChecked ( 1, true );
}
mTimerStartLabel = new QLabel( 0, 0, WType_Popup );
//mTimerStartLabel->setCaption( "Timer started!");
mTimerStartLabel->setAlignment ( Qt::AlignCenter ) ;
saveSlot( 1 );
}
SimpleAlarmDaemonImpl::~SimpleAlarmDaemonImpl()
{
//delete mPopUp;
delete mAlarmDialog;
delete mTimerStartLabel;
}
void SimpleAlarmDaemonImpl::saveSlot( int load )
{
QString fileName = QDir::homeDirPath() +"/.kopialarmrc";
//qDebug("save %d ", load );
QFile file( fileName );
if ( load ) {
mPopupFontSize = mTimerPopUp->font().pointSize();
confFontSize( mPopupFontSize );
if( !QFile::exists( fileName) )
return;
if (!file.open( IO_ReadOnly ) ) {
return ;
}
QString line;
bool ok;
int val;
int len;
while ( file.readLine( line, 1024 ) > 0 ) {
//qDebug("read %s ", line.latin1());
len = line.length();
if ( line.left(4 ) == "PPAU" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok ) {
confPause( val );
}
}
if ( line.left(4 ) == "POFO" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok ) {
confFontSize( val );
}
}
if ( line.left(4 ) == "SUCO" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok )
confSuspend ( val );
}
if ( line.left(4 ) == "WAAL" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok )
confSound( val );
}
if ( line.left(4 ) == "PLBE" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok )
slotPlayBeep( val );
}
if ( line.left(4 ) == "CUTE" ) {
mCustomText = line.mid( 5,len-6);
// qDebug("text ***%s*** ",mCustomText.latin1() );
}
if ( line.left(4 ) == "CUMI" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok )
mCustomMinutes = val;
}
if ( line.left(4 ) == "SUTI" ) {
val = line.mid( 4,len-5).toInt( &ok );
if ( ok )
mAlarmDialog->setSuspendTime( val );;
}
}
file.close();
} else {
if (!file.open( IO_WriteOnly ) ) {
return;
}
QString configString ;
configString += "PPAU " + QString::number( mPausePlay ) + "\n";
configString += "SUCO " + QString::number( mSuspend ) + "\n";
configString += "POFO " + QString::number( mPopupFontSize ) + "\n";
configString += "WAAL " + QString::number( wavAlarm ) + "\n";
configString += "PLBE " + QString::number( mPlayBeeps ) + "\n";
configString += "CUTE " + mCustomText + "\n";
configString += "CUMI " + QString::number( mCustomMinutes ) + "\n";
configString += "SUTI " + QString::number( mAlarmDialog->getSuspendTime( )) + "\n";
QTextStream ts( &file );
ts << configString ;
file.close();
}
}
void SimpleAlarmDaemonImpl::confSuspend( int num )
{
mSuspendPopUp->setItemChecked ( mSuspend,false );
mSuspend = num;
mSuspendPopUp->setItemChecked ( mSuspend,true );
}
void SimpleAlarmDaemonImpl::confPause( int num )
{
mPausePopUp->setItemChecked ( mPausePlay,false );
mPausePlay = num;
mPausePopUp->setItemChecked ( mPausePlay,true );
}
void SimpleAlarmDaemonImpl::confSound( int num )
{
if ( num == 0 ) {
wavAlarm = false;
mSoundPopUp->setItemChecked ( 0, true );
mSoundPopUp->setItemChecked ( 1, false );
} else {
wavAlarm = true;
mSoundPopUp->setItemChecked ( 0, false );
mSoundPopUp->setItemChecked ( 1, true );
}
}
void SimpleAlarmDaemonImpl::slotPlayBeep( int num )
{
if ( num == 1000 ) {
simulate();
return;
}
mBeepPopUp->setItemChecked ( mPlayBeeps,false );
mPlayBeeps = num;
mBeepPopUp->setItemChecked ( mPlayBeeps, true );
}
void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& )
{
//qDebug("SimpleAlarmDaemonImpl::ALARM RECEIVED! %s", msg.data());
QString mess = QString::fromUtf8(msg.data());
mAlarmMessage = mess.mid( 9 );
QString filename = getenv("QPEDIR") ;
filename += "/pics/kdepim/korganizer/koalarm.wav";
QString tempfilename;
if ( mess.left( 13 ) == "suspend_alarm") {
bool error = false;
int len = mess.mid( 13 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 13, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( ! error ) {
filename = tempfilename;
}
mAlarmMessage = mess.mid( 13+len+3 );
//qDebug("suspend file %s ",tempfilename.latin1() );
startAlarm( mAlarmMessage, filename);
return;
}
if ( mess.left( 11 ) == "timer_alarm") {
mTimerTime = 0;
startAlarm( mess.mid( 11 ), filename );
return;
}
if ( mess.left( 10 ) == "proc_alarm") {
bool error = false;
int len = mess.mid( 10 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 10, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( error ) {
mAlarmMessage = "Procedure Alarm\nError - File not found\n";
mAlarmMessage += mess.mid( 10+len+3+9 );
} else {
//qDebug("-----system command %s ",tempfilename.latin1() );
if ( vfork () == 0 ) {
execl ( tempfilename.latin1(), 0 );
return;
}
QTimer::singleShot( 2000, this, SLOT ( writeFile() ) );
return;
}
//qDebug("+++++++system command %s ",tempfilename.latin1() );
}
if ( mess.left( 11 ) == "audio_alarm") {
bool error = false;
int len = mess.mid( 11 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 11, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( ! error ) {
filename = tempfilename;
}
mAlarmMessage = mess.mid( 11+len+3+9 );
//qDebug("audio file command %s ",tempfilename.latin1() );
}
if ( mess.left( 9 ) == "cal_alarm") {
mAlarmMessage = mess.mid( 9 ) ;
}
QTimer::singleShot( 2000, this, SLOT ( writeFile() ) );
startAlarm( mAlarmMessage, filename );
}
int SimpleAlarmDaemonImpl::getFileNameLen( QString mess )
{
return 0;
}
void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename )
{
//mAlarmDialog->show();
//mAlarmDialog->raise();
mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend );
}
void SimpleAlarmDaemonImpl::fillTimerPopUp()
{
// qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime );
if ( mTimerPopupConf == mTimerTime ) {
if ( mTimerTime ) {
int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
QTime t ( secs/3600, (secs/60)%60, secs%60 );
mTimerPopUp->changeItem ( 1 , t.toString() + " (countdown)");
}
else {
QString text = mCustomText.stripWhiteSpace ();
int in = text.find( " " );
text = text.left ( in );
mTimerPopUp->changeItem ( 3, text );
}
return;
}
mTimerPopupConf = mTimerTime;
mTimerPopUp->clear();
if ( mTimerTime ) {
int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
QTime t ( secs/3600, (secs/60)%60, secs%60 );
mTimerPopUp->insertItem( "Stop timer "+ mRunningTimerText , 0 );
mTimerPopUp->insertItem( t.toString() + " (countdown)",1);
mTimerPopUp->insertItem( mRunningTimer.time().toString() + " (alarm)",2);
} else {
QString fileName = QDir::homeDirPath() +"/.kopialarmtimerrc";
QFile file( fileName );
if( !QFile::exists( fileName) ) {
// write defaults
if (!file.open( IO_WriteOnly ) ) {
return;
}
QString configString ;
configString += "#config file for kopi alarm timer\n";
configString += "#format: <Text for popup menu>;<timer countdown in minutes>\n";
configString += "24 hours; 1440\n";
configString += "9 hours; 540\n";
configString += "8 hours; 480\n";
configString += "1 hour; 60\n";
configString += "30 min; 30\n";
configString += "15 min; 15\n";
configString += "SEPARATOR\n";
configString += "Pizza; 22\n";
configString += "Nap; 45\n";
configString += "Tea; 5\n";
QTextStream ts( &file );
ts << configString ;
file.close();
}
if (!file.open( IO_ReadOnly ) ) {
return ;
}
QString line;
bool ok;
while ( file.readLine( line, 1024 ) > 0 ) {
//qDebug("read %s ", line.latin1());
if ( line.left(1 ) != "#" ) {
// no comment
if ( line.left(9 ) == "SEPARATOR" ) {
mTimerPopUp->insertSeparator();
} else {
QStringList li = QStringList::split(";",line);
ok = false;
if ( li.count() == 2 ) {
int val = li[1].toInt( &ok );
if ( ok && val > 0 ) {
mTimerPopUp->insertItem( li[0], val+10);
}
}
}
}
}
file.close();
#if 0
mTimerPopUp->insertItem( "24 hours", 1440 );
// mTimerPopUp->insertItem( i18n("12 h"), 720 );
mTimerPopUp->insertItem( " 8 hours", 480 );
mTimerPopUp->insertItem( " 5 hours", 300 );
// mTimerPopUp->insertItem( i18n(" 2 h"), 120 );
mTimerPopUp->insertItem( " 1 hour", 60 );
mTimerPopUp->insertItem( "30 min", 30 );
mTimerPopUp->insertItem( "15 min", 15 );
mTimerPopUp->insertItem( "10 min", 10 );
//mTimerPopUp->insertItem( " 5 min", 5 );
mTimerPopUp->insertSeparator();
mTimerPopUp->insertItem( "Pizza", 22 );
mTimerPopUp->insertItem( "Nap", 45 );
mTimerPopUp->insertItem( "Tea", 5 );
#endif
QString text = mCustomText.stripWhiteSpace ();
int in = text.find( " " );
text = text.left ( in );
mTimerPopUp->insertItem( text, 3 );
mTimerPopUp->insertSeparator();
mTimerPopUp->insertItem( "Customize", 2 );
}
}
void SimpleAlarmDaemonImpl::showTimer()
{
fillTimerPopUp();
}