~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/psioptions.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 */
20
20
 
 
21
#include "psioptions.h"
 
22
 
21
23
#include <QCoreApplication>
 
24
#include <QTimer>
22
25
 
23
 
#include "psioptions.h"
24
26
#include "applicationinfo.h"
25
27
#include "xmpp_xmlcommon.h"
26
28
#include "xmpp_task.h"
27
29
#include "xmpp_jid.h"
28
30
#include "xmpp_client.h"
 
31
#include "statuspreset.h"
 
32
#include "psitoolbar.h"
 
33
#include "common.h"
29
34
 
30
35
using namespace XMPP;
31
36
 
107
112
}
108
113
 
109
114
/**
 
115
 * Returns the instance of this class containing default values of all options
 
116
 * \return Instance of PsiOptions
 
117
 */
 
118
const PsiOptions* PsiOptions::defaults()
 
119
{
 
120
        if ( !defaults_ )
 
121
                defaults_ = new PsiOptions();
 
122
        return defaults_;
 
123
}
 
124
 
 
125
/**
 
126
 * Reset the singleton instance of this class
 
127
 * this delete the old instance so be sure no references are there anymore
 
128
 */
 
129
void PsiOptions::reset() {
 
130
        instance_ = 0;
 
131
        delete instance_;
 
132
}
 
133
 
 
134
 
 
135
/**
 
136
 * initizialises the default options for a new profile
 
137
 */
 
138
bool PsiOptions::newProfile()
 
139
{
 
140
        bool ok = true;
 
141
        if (!load(":/options/newprofile.xml")) {
 
142
                ok = false;
 
143
        }
 
144
        StatusPreset(tr("Away from desk"),
 
145
                     tr("I am away from my desk.  Leave a message."),
 
146
                     XMPP::Status::Away
 
147
                    ).toOptions(this);
 
148
        StatusPreset(tr("Showering"),
 
149
                     tr("I'm in the shower.  You'll have to wait for me to get out."),
 
150
                     XMPP::Status::Away
 
151
                    ).toOptions(this);
 
152
        StatusPreset(tr("Eating"),
 
153
                     tr("Out eating.  Mmmm.. food."),
 
154
                     XMPP::Status::Away
 
155
                    ).toOptions(this);
 
156
        StatusPreset(tr("Sleep"),
 
157
                     tr("Sleep is good.  Zzzzz"),
 
158
                     XMPP::Status::DND
 
159
                    ).toOptions(this);
 
160
        StatusPreset(tr("Work"),
 
161
                     tr("Can't chat.  Gotta work."),
 
162
                     XMPP::Status::DND
 
163
                    ).toOptions(this);
 
164
        StatusPreset(tr("Air"),
 
165
                     tr("Stepping out to get some fresh air."),
 
166
                     XMPP::Status::Away
 
167
                    ).toOptions(this);
 
168
        StatusPreset(tr("Movie"),
 
169
                     tr("Out to a movie.  Is that OK with you?"),
 
170
                     XMPP::Status::Away
 
171
                    ).toOptions(this);
 
172
        StatusPreset(tr("Secret"),
 
173
                     tr("I'm not available right now and that's all you need to know."),
 
174
                     XMPP::Status::XA
 
175
                    ).toOptions(this);
 
176
        StatusPreset(tr("Out for the night"),
 
177
                     tr("Out for the night."),
 
178
                     XMPP::Status::Away
 
179
                    ).toOptions(this);
 
180
        StatusPreset(tr("Greece"),
 
181
                     tr("I have gone to a far away place.  I will be back someday!"),
 
182
                     XMPP::Status::XA
 
183
                    ).toOptions(this);
 
184
 
 
185
        {
 
186
                ToolbarPrefs buttons;
 
187
                buttons.name = tr("Buttons");
 
188
#ifndef Q_WS_MAC
 
189
                buttons.on = true;
 
190
#endif
 
191
                buttons.keys << "button_options" << "button_status";
 
192
                buttons.dock = Qt::DockBottom;
 
193
 
 
194
                ToolbarPrefs showContacts;
 
195
                showContacts.name = tr("Show contacts");
 
196
                showContacts.keys << "show_offline" << "show_hidden" << "show_agents" << "show_self" << "show_statusmsg";
 
197
 
 
198
                ToolbarPrefs eventNotifier;
 
199
                eventNotifier.name = tr("Event notifier");
 
200
                eventNotifier.keys << "event_notifier";
 
201
                eventNotifier.dock = Qt::DockBottom;
 
202
 
 
203
                QList<ToolbarPrefs> toolbars;
 
204
                toolbars << buttons
 
205
                         << showContacts
 
206
                         << eventNotifier;
 
207
                foreach(ToolbarPrefs tb, toolbars) {
 
208
                        tb.locked = true;
 
209
                        PsiToolBar::structToOptions(this, tb);
 
210
                }
 
211
        }
 
212
 
 
213
        setOption("options.status.auto-away.message", tr("Auto Status (idle)"));
 
214
        
 
215
        return ok;
 
216
}
 
217
 
 
218
 
 
219
/**
110
220
 * Loads the options present in the xml config file named.
111
221
 * \param file Name of the xml config file to load
112
222
 * \return Success
139
249
        return saveOptions(file, "options", ApplicationInfo::optionsNS(), ApplicationInfo::version());
140
250
}
141
251
 
142
 
/**
143
 
 * Default (private) constructor
144
 
 */
145
252
PsiOptions::PsiOptions()
146
253
        : OptionsTree()
 
254
        , autoSaveTimer_(0)
147
255
{
 
256
        autoSaveTimer_ = new QTimer(this);
 
257
        autoSaveTimer_->setSingleShot(true);
 
258
        autoSaveTimer_->setInterval(1000);
 
259
        connect(autoSaveTimer_, SIGNAL(timeout()), SLOT(saveToAutoFile()));
 
260
 
148
261
        setParent(QCoreApplication::instance());
149
262
        autoSave(false);
 
263
 
150
264
        if (!load(":/options/default.xml"))
151
265
                qWarning("ERROR: Failed to load default options");
152
266
#ifdef Q_WS_MAC
159
273
#endif
160
274
}
161
275
 
162
 
/**
163
 
 * Boom (Destructor)
164
 
 */
165
276
PsiOptions::~PsiOptions()
166
277
{
167
 
        
 
278
        // since we queue connection to saveToAutoFile, so if some option was saved prior
 
279
        // to program termination, the PsiOptions is never given the chance to save
 
280
        // the changed option
 
281
        if (!autoFile_.isEmpty()) {
 
282
                saveToAutoFile();
 
283
        }
168
284
}
169
285
 
170
286
/**
176
292
void PsiOptions::autoSave(bool autoSave, QString autoFile)
177
293
{
178
294
        if (autoSave) {
179
 
                connect(this, SIGNAL(optionChanged(const QString&)), SLOT(saveToAutoFile()));
180
 
                autoFile_=autoFile;
 
295
                connect(this, SIGNAL(optionChanged(const QString&)), autoSaveTimer_, SLOT(start()));
 
296
                autoFile_ = autoFile;
181
297
        }
182
298
        else {
183
 
                disconnect(this, SLOT(saveToAutoFile()));
184
 
                autoFile="";
 
299
                disconnect(this, SIGNAL(optionChanged(const QString&)), autoSaveTimer_, SLOT(start()));
 
300
                autoFile = "";
185
301
        }
186
 
                
187
 
        
188
302
}
189
303
 
190
304
/**
192
306
 */
193
307
void PsiOptions::saveToAutoFile()
194
308
{
195
 
        if (autoFile_ != "")
 
309
        if (autoFile_ != "") {
196
310
                save(autoFile_);
 
311
        }
197
312
}
198
313
 
199
314
/**
210
325
}
211
326
 
212
327
PsiOptions* PsiOptions::instance_ = NULL;
 
328
PsiOptions* PsiOptions::defaults_ = NULL;
213
329