Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

datebooksettings.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "datebooksettings.h"
00032 
00033 #include <opie2/opluginloader.h>
00034 #include <opie2/odebug.h>
00035 #include <opie2/oholidaypluginif.h>
00036 #include <opie2/oholidayplugin.h>
00037 #include <opie2/oholidayplugincfgwidget.h>
00038 
00039 #include <qpe/qpeapplication.h>
00040 
00041 #include <qspinbox.h>
00042 #include <qcheckbox.h>
00043 #include <qlistview.h>
00044 #include <qheader.h>
00045 #include <qtabwidget.h>
00046 #include <qlayout.h>
00047 
00048 DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent,
00049                                     const char *name, bool modal, WFlags fl )
00050     : DateBookSettingsBase( parent, name, modal, fl ),
00051       ampm( whichClock )
00052 {
00053     init();
00054     QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) );
00055     QArray<int> categories;
00056     comboCategory->setCategories( categories, "Calendar", tr("Calendar") );
00057     m_loader = 0;
00058     m_manager = 0;
00059     m_PluginListView->header()->hide();
00060     m_PluginListView->setSorting(-1);
00061 }
00062 
00063 DateBookSettings::~DateBookSettings()
00064 {
00065 }
00066 
00067 void DateBookSettings::setStartTime( int newStartViewTime )
00068 {
00069     if ( ampm ) {
00070     if ( newStartViewTime >= 12 ) {
00071         newStartViewTime %= 12;
00072         if ( newStartViewTime == 0 )
00073         newStartViewTime = 12;
00074         spinStart->setSuffix( tr(":00 PM") );
00075     }
00076     else if ( newStartViewTime == 0 ) {
00077         newStartViewTime = 12;
00078         spinStart->setSuffix( tr(":00 AM") );
00079     }
00080     oldtime = newStartViewTime;
00081     }
00082     spinStart->setValue( newStartViewTime );
00083 }
00084 
00085 int DateBookSettings::startTime() const
00086 {
00087     int returnMe = spinStart->value();
00088     if ( ampm ) {
00089     if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) )
00090         returnMe += 12;
00091     else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE))
00092         returnMe = 0;
00093     }
00094     return returnMe;
00095 }
00096 
00097 void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader)
00098 {
00099     m_manager = aManager;
00100     m_loader = aLoader;
00101     if (!aManager||!aLoader) return;
00102     Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true);
00103     QCheckListItem *pitem = 0;
00104 
00105     for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) {
00106         pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox);
00107         pitem->setOn( (*it).isEnabled() );
00108 
00109         Opie::Datebook::HolidayPluginIf*hif = m_loader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN);
00110         if (!hif) continue;
00111         Opie::Datebook::HolidayPlugin*pl = hif->plugin();
00112         if (!pl) continue;
00113         Opie::Datebook::HolidayPluginConfigWidget*cfg = pl->configWidget();
00114         if (!cfg) continue;
00115         QWidget * dtab = new QWidget(TabWidget,pl->description());
00116         QVBoxLayout*dlayout = new QVBoxLayout(dtab);
00117         dlayout->setMargin(2);
00118         dlayout->setSpacing(2);
00119         cfg->reparent(dtab,0,QPoint(0,0));
00120         dlayout->addWidget(cfg);
00121         TabWidget->insertTab(dtab,pl->description());
00122 
00123         m_cfgWidgets.append(cfg);
00124     }
00125 }
00126 void DateBookSettings::savePlugins()
00127 {
00128     QValueList<Opie::Datebook::HolidayPluginConfigWidget*>::Iterator it;
00129     for (it=m_cfgWidgets.begin();it!=m_cfgWidgets.end();++it) {
00130         (*it)->saveConfig();
00131     }
00132 }
00133 
00134 void DateBookSettings::pluginItemClicked(QListViewItem *aItem)
00135 {
00136     if (!aItem||!m_manager||!m_loader) return;
00137     QCheckListItem*pitem = ((QCheckListItem*)aItem);
00138 
00139     Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true );
00140     for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00141         if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) {
00142             m_manager->setEnabled((*it),pitem->isOn());
00143             break;
00144         }
00145     }
00146 }
00147 
00148 void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime )
00149 {
00150     chkAlarmPreset->setChecked( bAlarm );
00151     if ( presetTime >=5 )
00152     spinPreset->setValue( presetTime );
00153 }
00154 
00155 bool DateBookSettings::alarmPreset() const
00156 {
00157     return chkAlarmPreset->isChecked();
00158 }
00159 
00160 int DateBookSettings::presetTime() const
00161 {
00162     return spinPreset->value();
00163 }
00164 
00165 
00166 void DateBookSettings::slot12Hour( int i )
00167 {
00168     if ( ampm ) {
00169     if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) {
00170         if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
00171         spinStart->setSuffix( tr(":00 PM") );
00172     } else {
00173         if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
00174         spinStart->setSuffix( tr(":00 AM") );
00175     }
00176     oldtime = i;
00177     }
00178 }
00179 
00180 void DateBookSettings::init()
00181 {
00182     if ( ampm ) {
00183     spinStart->setMinValue( 1 );
00184     spinStart->setMaxValue( 12 );
00185     spinStart->setValue( 12 );
00186     spinStart->setSuffix( tr(":00 AM") );
00187     oldtime = 12;
00188     } else {
00189     spinStart->setMinValue( 0 );
00190     spinStart->setMaxValue( 23 );
00191     spinStart->setSuffix( tr(":00") );
00192     }
00193 }
00194 
00195 void DateBookSettings::slotChangeClock( bool whichClock )
00196 {
00197     int saveMe;
00198     saveMe = spinStart->value();
00199     if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) {
00200     if ( saveMe == 12 )
00201         saveMe = 0;
00202     } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE )  ) {
00203     if ( saveMe != 12 )
00204         saveMe += 12;
00205     }
00206     ampm = whichClock;
00207     init();
00208     setStartTime( saveMe );
00209 }
00210 
00211 void DateBookSettings::setJumpToCurTime( bool bJump )
00212 {
00213     chkJumpToCurTime->setChecked( bJump );
00214 }
00215 
00216 bool DateBookSettings::jumpToCurTime() const
00217 {
00218     return chkJumpToCurTime->isChecked();
00219 }
00220 
00221 void DateBookSettings::setRowStyle( int style )
00222 {
00223     comboRowStyle->setCurrentItem( style );
00224 }
00225 
00226 int DateBookSettings::rowStyle() const
00227 {
00228     return comboRowStyle->currentItem();
00229 }

Generated on Sat Nov 5 16:15:48 2005 for OPIE by  doxygen 1.4.2