~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to src/profiledlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2010-02-19 09:37:12 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100219093712-e225xvm1wjcf1cgi
Tags: 0.14-2
* comment out only function which uses va_list to work around build
  problems on armel
* Set Standards-Version to 3.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QMessageBox>
29
29
#include <QCheckBox>
30
30
#include <QPushButton>
31
 
#include <Q3Button>
32
 
#include <Q3GroupBox>
33
 
#include <Q3ListBox>
34
31
#include <QInputDialog>
35
32
#include <QFile>
36
33
#include <QFileInfo>
37
 
#include <Q3ButtonGroup>
38
34
#include <QPixmap>
 
35
#include <QButtonGroup>
 
36
 
39
37
#include "profiles.h"
40
38
#include "common.h"
41
39
#include "iconwidget.h"
44
42
class StretchLogoLabel : public QLabel
45
43
{
46
44
public:
47
 
        StretchLogoLabel(QPixmap pix, QWidget *label, const char *name = 0)
48
 
        : QLabel((QWidget*)label->parent(), name)
 
45
        StretchLogoLabel(QPixmap pix, QWidget *label)
 
46
                : QLabel(label->parentWidget())
 
47
                , pixmap_(pix)
49
48
        {
50
 
                setPixmap(pix);
51
 
                setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
52
49
                replaceWidget(label, this);
 
50
                setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
 
51
        }
 
52
 
 
53
        // reimplemented
 
54
        QSize sizeHint() const
 
55
        {
 
56
                QSize sh = QLabel::sizeHint();
 
57
                sh.setHeight(pixmap_.height());
 
58
                return sh;
53
59
        }
54
60
 
55
61
        void paintEvent(QPaintEvent *event)
56
62
        {
57
 
                QPainter *p = new QPainter(this);
58
 
                p->drawTiledPixmap(0, 0, width(), height(), *pixmap());
59
 
                delete p;
60
 
                QLabel::paintEvent(event);
 
63
                QPainter p(this);
 
64
                p.fillRect(rect(), Qt::red);
 
65
                p.drawTiledPixmap(0, 0, width(), height(), pixmap_);
61
66
        }
 
67
 
 
68
private:
 
69
        QPixmap pixmap_;
62
70
};
63
71
 
 
72
//----------------------------------------------------------------------------
 
73
// ProfileOpenDlg
 
74
//----------------------------------------------------------------------------
 
75
 
64
76
ProfileOpenDlg::ProfileOpenDlg(const QString &def, const VarList &_langs, const QString &curLang, QWidget *parent)
65
77
:QDialog(parent)
66
78
{
67
79
        setupUi(this);
68
80
        setModal(true);
69
 
        setWindowTitle(CAP(caption()));
 
81
        setWindowTitle(CAP(windowTitle()));
70
82
        pb_open->setDefault(true);
71
83
 
72
84
        langs = _langs;
73
85
 
74
 
        // insert the logo
75
86
        QPixmap logo = (QPixmap)IconsetFactory::icon("psi/psiLogo").pixmap();
76
87
        lb_logo->setPixmap(logo);
77
88
        lb_logo->setFixedSize(logo.width(), logo.height());
78
89
        lb_logo->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
79
90
        //setFixedWidth(logo->width());
80
91
 
81
 
        QImage logoImg = logo.convertToImage();
82
 
 
83
 
        QPixmap tmp;
84
 
        tmp.convertFromImage( logoImg.copy(0, 0, 1, logoImg.height()) );
85
 
        StretchLogoLabel *stretch = new StretchLogoLabel(tmp, lb_left);
86
 
 
87
 
        tmp.convertFromImage( logoImg.copy(logoImg.width()-1, 0, 1, logoImg.height()) );
88
 
        stretch = new StretchLogoLabel(tmp, lb_right);
89
 
 
90
 
        // setup signals
 
92
        QImage logoImg = logo.toImage();
 
93
        new StretchLogoLabel(QPixmap::fromImage( logoImg.copy(0, 0, 1, logoImg.height()) ), lb_left);
 
94
        new StretchLogoLabel(QPixmap::fromImage( logoImg.copy(logoImg.width()-1, 0, 1, logoImg.height()) ), lb_right);
 
95
 
91
96
        connect(pb_open, SIGNAL(clicked()), SLOT(accept()));
92
97
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
93
98
        connect(pb_profiles, SIGNAL(clicked()), SLOT(manageProfiles()));
96
101
        int x = 0;
97
102
        langSel = x;
98
103
        for(VarList::ConstIterator it = langs.begin(); it != langs.end(); ++it) {
99
 
                cb_lang->insertItem((*it).data());
 
104
                cb_lang->addItem((*it).data());
100
105
                if((curLang.isEmpty() && x == 0) || (curLang == (*it).key())) {
101
 
                        cb_lang->setCurrentItem(x);
 
106
                        cb_lang->setCurrentIndex(x);
102
107
                        langSel = x;
103
108
                }
104
109
                ++x;
105
110
        }
106
111
 
107
 
        // QWhatsThis helpers
108
112
        cb_profile->setWhatsThis(
109
113
                tr("Select a profile to open from this list."));
110
114
        cb_lang->setWhatsThis(
135
139
        else {
136
140
                int x = 0;
137
141
                for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
138
 
                        cb_profile->insertItem(*it);
 
142
                        cb_profile->addItem(*it);
139
143
                        if((choose.isEmpty() && x == 0) || (choose == *it)) {
140
 
                                cb_profile->setCurrentItem(x);
 
144
                                cb_profile->setCurrentIndex(x);
141
145
                        }
142
146
                        ++x;
143
147
                }
152
156
{
153
157
        ProfileManageDlg *w = new ProfileManageDlg(cb_profile->currentText(), this);
154
158
        w->exec();
155
 
        QString last = w->lbx_profiles->text(w->lbx_profiles->currentItem());
 
159
        QString last = w->lbx_profiles->currentItem()->text();
156
160
        delete w;
157
161
 
158
162
        reload(last);
169
173
        done(10);
170
174
}
171
175
 
 
176
//----------------------------------------------------------------------------
 
177
// ProfileManageDlg
 
178
//----------------------------------------------------------------------------
172
179
 
173
180
ProfileManageDlg::ProfileManageDlg(const QString &choose, QWidget *parent)
174
181
:QDialog(parent)
175
182
{
176
183
        setupUi(this);
177
184
        setModal(true);
178
 
        setWindowTitle(CAP(caption()));
 
185
        setWindowTitle(CAP(windowTitle()));
179
186
 
180
187
        // setup signals
181
188
        connect(pb_new, SIGNAL(clicked()), SLOT(slotProfileNew()));
182
189
        connect(pb_rename, SIGNAL(clicked()), SLOT(slotProfileRename()));
183
190
        connect(pb_delete, SIGNAL(clicked()), SLOT(slotProfileDelete()));
184
 
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
185
 
        connect(lbx_profiles, SIGNAL(highlighted(int)), SLOT(updateSelection()));
 
191
        connect(lbx_profiles, SIGNAL(currentRowChanged(int)), SLOT(updateSelection()));
186
192
 
187
193
        // load the listing
188
194
        QStringList list = getProfilesList();
189
195
        int x = 0;
190
196
        for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
191
 
                lbx_profiles->insertItem(*it);
 
197
                lbx_profiles->addItem(*it);
192
198
                if(*it == choose)
193
 
                        lbx_profiles->setCurrentItem(x);
 
199
                        lbx_profiles->setCurrentRow(x);
194
200
                ++x;
195
201
        }
196
202
 
206
212
        if(r == QDialog::Accepted) {
207
213
                name = w->name;
208
214
 
209
 
                lbx_profiles->insertItem(name);
210
 
                lbx_profiles->setCurrentItem(lbx_profiles->count()-1);
 
215
                lbx_profiles->addItem(name);
 
216
                lbx_profiles->setCurrentRow(lbx_profiles->count()-1);
211
217
        }
212
218
        delete w;
213
219
 
218
224
 
219
225
void ProfileManageDlg::slotProfileRename()
220
226
{
221
 
        int x = lbx_profiles->currentItem();
 
227
        int x = lbx_profiles->currentRow();
222
228
        if(x == -1)
223
229
                return;
224
230
 
225
 
        QString oldname = lbx_profiles->text(x);
 
231
        QString oldname = lbx_profiles->item(x)->text();
226
232
        QString name;
227
233
 
228
234
        while(1) {
229
235
                bool ok = false;
230
 
                name = QInputDialog::getText(CAP(tr("Rename Profile")), tr("Please enter a new name for the profile.  Keep it simple.\nOnly use letters or numbers.  No punctuation or spaces."), QLineEdit::Normal, name, &ok, this);
 
236
                name = QInputDialog::getText(this, CAP(tr("Rename Profile")), tr("Please enter a new name for the profile.  Keep it simple.\nOnly use letters or numbers.  No punctuation or spaces."), QLineEdit::Normal, name, &ok);
231
237
                if(!ok)
232
238
                        return;
233
239
 
242
248
                break;
243
249
        }
244
250
 
245
 
        lbx_profiles->changeItem(name, x);
 
251
        lbx_profiles->item(x)->setText(name);
246
252
}
247
253
 
248
254
void ProfileManageDlg::slotProfileDelete()
249
255
{
250
 
        int x = lbx_profiles->currentItem();
 
256
        int x = lbx_profiles->currentRow();
251
257
        if(x == -1)
252
258
                return;
253
 
        QString name = lbx_profiles->text(x);
 
259
        QString name = lbx_profiles->item(x)->text();
254
260
        QString path = ApplicationInfo::profilesDir() + "/" + name;
255
261
 
256
262
        // prompt first
283
289
                        return;
284
290
                }
285
291
 
286
 
                lbx_profiles->removeItem(x);
 
292
                // FIXME
 
293
                delete lbx_profiles->item(x);
287
294
        }
288
295
}
289
296
 
290
297
void ProfileManageDlg::updateSelection()
291
298
{
292
 
        int x = lbx_profiles->currentItem();
 
299
        int x = lbx_profiles->currentRow();
293
300
 
294
301
        if(x == -1) {
295
 
                pb_rename->setEnabled(false);
 
302
                // pb_rename->setEnabled(false);
296
303
                pb_delete->setEnabled(false);
297
304
        }
298
305
        else {
299
 
                pb_rename->setEnabled(true);
 
306
                // pb_rename->setEnabled(true);
300
307
                pb_delete->setEnabled(true);
301
308
        }
302
309
}
303
310
 
 
311
//----------------------------------------------------------------------------
 
312
// ProfileNewDlg
 
313
//----------------------------------------------------------------------------
304
314
 
305
315
ProfileNewDlg::ProfileNewDlg(QWidget *parent)
306
316
:QDialog(parent)
307
317
{
308
318
        setupUi(this);
309
319
        setModal(true);
310
 
        setWindowTitle(CAP(caption()));
311
 
 
312
 
        bg_defAct->setButton(bg_defAct->id((Q3Button *)rb_chat));
 
320
        setWindowTitle(CAP(windowTitle()));
 
321
 
 
322
        buttonGroup_ = new QButtonGroup(this);
 
323
        buttonGroup_->addButton(rb_message, 0);
 
324
        buttonGroup_->addButton(rb_chat, 1);
 
325
        rb_chat->setChecked(true);
 
326
 
313
327
        le_name->setFocus();
314
328
 
315
329
        connect(pb_create, SIGNAL(clicked()), SLOT(slotCreate()));
341
355
        }
342
356
        
343
357
        
344
 
        o.setOption("options.messages.default-outgoing-message-type" ,bg_defAct->selected() == (Q3Button *)rb_message ? "message": "chat");
 
358
        o.setOption("options.messages.default-outgoing-message-type" ,rb_message->isChecked() ? "message": "chat");
345
359
        o.setOption("options.ui.emoticons.use-emoticons" ,ck_useEmoticons->isChecked());
346
360
        o.save(pathToProfile(name) + "/options.xml");
347
361