summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebooksettings.cpp
blob: c72cd5985c37758fe7dd9b1974c80cd3508578a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
                             This file is part of the Opie Project

                             Copyright (C) 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 "datebooksettings.h"

#include <opie2/opluginloader.h>
#include <opie2/odebug.h>
#include <opie2/oholidaypluginif.h>
#include <opie2/oholidayplugin.h>
#include <opie2/oholidayplugincfgwidget.h>

#include <qpe/qpeapplication.h>

#include <qspinbox.h>
#include <qcheckbox.h>
#include <qlistview.h>
#include <qheader.h>
#include <qtabwidget.h>
#include <qlayout.h>

DateBookSettings::DateBookSettings( bool whichClock, QWidget *parent,
                                    const char *name, bool modal, WFlags fl )
    : DateBookSettingsBase( parent, name, modal, fl ),
      ampm( whichClock )
{
    init();
    QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( slotChangeClock(bool) ) );
    QArray<int> categories;
    comboCategory->setCategories( categories, "Calendar", tr("Calendar") );
    m_loader = 0;
    m_manager = 0;
    m_PluginListView->header()->hide();
    m_PluginListView->setSorting(-1);
}

DateBookSettings::~DateBookSettings()
{
}

void DateBookSettings::setStartTime( int newStartViewTime )
{
    if ( ampm ) {
    if ( newStartViewTime >= 12 ) {
        newStartViewTime %= 12;
        if ( newStartViewTime == 0 )
        newStartViewTime = 12;
        spinStart->setSuffix( tr(":00 PM") );
    }
    else if ( newStartViewTime == 0 ) {
        newStartViewTime = 12;
        spinStart->setSuffix( tr(":00 AM") );
    }
    oldtime = newStartViewTime;
    }
    spinStart->setValue( newStartViewTime );
}

int DateBookSettings::startTime() const
{
    int returnMe = spinStart->value();
    if ( ampm ) {
    if ( returnMe != 12 && spinStart->suffix().contains(tr("PM"), FALSE) )
        returnMe += 12;
    else if (returnMe == 12 && spinStart->suffix().contains(tr("AM"), TRUE))
        returnMe = 0;
    }
    return returnMe;
}

void DateBookSettings::setPluginList(Opie::Core::OPluginManager*aManager,Opie::Core::OPluginLoader*aLoader)
{
    m_manager = aManager;
    m_loader = aLoader;
    if (!aManager||!aLoader) return;
    Opie::Core::OPluginItem::List inLst = m_loader->allAvailable(true);
    QCheckListItem *pitem = 0;

    for ( Opie::Core::OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) {
        pitem = new QCheckListItem(m_PluginListView,(*it).name(),QCheckListItem::CheckBox);
        pitem->setOn( (*it).isEnabled() );

        Opie::Datebook::HolidayPluginIf*hif = m_loader->load<Opie::Datebook::HolidayPluginIf>(*it,IID_HOLIDAY_PLUGIN);
        if (!hif) continue;
        Opie::Datebook::HolidayPlugin*pl = hif->plugin();
        if (!pl) continue;
        Opie::Datebook::HolidayPluginConfigWidget*cfg = pl->configWidget();
        if (!cfg) continue;
        QWidget * dtab = new QWidget(TabWidget,pl->description());
        QVBoxLayout*dlayout = new QVBoxLayout(dtab);
        dlayout->setMargin(2);
        dlayout->setSpacing(2);
        cfg->reparent(dtab,0,QPoint(0,0));
        dlayout->addWidget(cfg);
        TabWidget->insertTab(dtab,pl->description());

        m_cfgWidgets.append(cfg);
    }
}
void DateBookSettings::savePlugins()
{
    QValueList<Opie::Datebook::HolidayPluginConfigWidget*>::Iterator it;
    for (it=m_cfgWidgets.begin();it!=m_cfgWidgets.end();++it) {
        (*it)->saveConfig();
    }
}

void DateBookSettings::pluginItemClicked(QListViewItem *aItem)
{
    if (!aItem||!m_manager||!m_loader) return;
    QCheckListItem*pitem = ((QCheckListItem*)aItem);

    Opie::Core::OPluginItem::List lst = m_loader->allAvailable( true );
    for ( Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) {
        if ( QString::compare( (*it).name() , pitem->text(0) ) == 0 ) {
            m_manager->setEnabled((*it),pitem->isOn());
            break;
        }
    }
}

void DateBookSettings::setAlarmPreset( bool bAlarm, int presetTime )
{
    chkAlarmPreset->setChecked( bAlarm );
    if ( presetTime >=5 )
    spinPreset->setValue( presetTime );
}

bool DateBookSettings::alarmPreset() const
{
    return chkAlarmPreset->isChecked();
}

int DateBookSettings::presetTime() const
{
    return spinPreset->value();
}


void DateBookSettings::slot12Hour( int i )
{
    if ( ampm ) {
    if ( spinStart->suffix().contains( tr("AM"), FALSE ) ) {
        if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
        spinStart->setSuffix( tr(":00 PM") );
    } else {
        if ( oldtime == 12 && i == 11 || oldtime == 11 && i == 12 )
        spinStart->setSuffix( tr(":00 AM") );
    }
    oldtime = i;
    }
}

void DateBookSettings::init()
{
    if ( ampm ) {
    spinStart->setMinValue( 1 );
    spinStart->setMaxValue( 12 );
    spinStart->setValue( 12 );
    spinStart->setSuffix( tr(":00 AM") );
    oldtime = 12;
    } else {
    spinStart->setMinValue( 0 );
    spinStart->setMaxValue( 23 );
    spinStart->setSuffix( tr(":00") );
    }
}

void DateBookSettings::slotChangeClock( bool whichClock )
{
    int saveMe;
    saveMe = spinStart->value();
    if ( ampm && spinStart->suffix().contains( tr("AM"), FALSE ) ) {
    if ( saveMe == 12 )
        saveMe = 0;
    } else if ( ampm && spinStart->suffix().contains( tr("PM"), FALSE )  ) {
    if ( saveMe != 12 )
        saveMe += 12;
    }
    ampm = whichClock;
    init();
    setStartTime( saveMe );
}

void DateBookSettings::setJumpToCurTime( bool bJump )
{
    chkJumpToCurTime->setChecked( bJump );
}

bool DateBookSettings::jumpToCurTime() const
{
    return chkJumpToCurTime->isChecked();
}

void DateBookSettings::setRowStyle( int style )
{
    comboRowStyle->setCurrentItem( style );
}

int DateBookSettings::rowStyle() const
{
    return comboRowStyle->currentItem();
}