~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/statusdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** statusdlg.cpp - dialog for setting and reading status messages
3
 
** Copyright (C) 2001, 2002  Justin Karneges
4
 
**
5
 
** This program is free software; you can redistribute it and/or
6
 
** modify it under the terms of the GNU General Public License
7
 
** as published by the Free Software Foundation; either version 2
8
 
** of the License, or (at your option) any later version.
9
 
**
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
**
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 
**
19
 
****************************************************************************/
 
1
/*
 
2
 * statusdlg.cpp - dialogs for setting and reading status messages
 
3
 * Copyright (C) 2001, 2002  Justin Karneges
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
20
20
 
21
21
#include"statusdlg.h"
22
22
 
23
23
#include<qpushbutton.h>
24
24
#include<qlayout.h>
25
25
#include<qlabel.h>
26
 
 
27
 
 
28
 
StatusShowDlg::StatusShowDlg(UserListItem *i)
29
 
:QDialog(0,0,FALSE,WDestructiveClose)
30
 
{
31
 
        // build the dialog
32
 
        QVBoxLayout *vb = new QVBoxLayout(this, 8);
33
 
        MsgMle *te = new MsgMle(this);
34
 
        vb->addWidget(te);
35
 
        QHBoxLayout *hb = new QHBoxLayout(vb);
36
 
        QPushButton *pb = new QPushButton(tr("&Close"), this);
37
 
        pb->setMinimumWidth(80);
38
 
        hb->addStretch(1);
39
 
        hb->addWidget(pb);
40
 
        hb->addStretch(1);
41
 
 
42
 
        // set the rest up
43
 
        te->setReadOnly(TRUE);
44
 
        te->setTextFormat(RichText);
45
 
        te->setText(linkify(plain2rich(i->statusString)));
46
 
        connect(te, SIGNAL(linkClicked(const QString &)), SLOT(aOpenURL(const QString &)));
47
 
        connect(pb, SIGNAL(clicked()), SLOT(close()));
48
 
        pb->setFocus();
49
 
 
50
 
        QString nick;
51
 
        if(i->nick.isEmpty())
52
 
                nick = i->jid;
53
 
        else
54
 
                nick = i->nick;
55
 
 
56
 
        setCaption(QString(tr("Status for %1")).arg(nick));
57
 
 
58
 
        resize(400,240);
59
 
}
60
 
 
61
 
void StatusShowDlg::aOpenURL(const QString &url)
62
 
{
63
 
        openURL(url);
64
 
}
65
 
 
66
 
 
67
 
static int combomap[4] = { STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND };
68
 
 
69
 
StatusSetDlg::StatusSetDlg(StatusInfo *x_info)
70
 
:QDialog(0,0,TRUE)
71
 
{
72
 
        info = x_info;
73
 
 
74
 
        // build the dialog
75
 
        QVBoxLayout *vb = new QVBoxLayout(this, 8);
 
26
#include<qcombobox.h>
 
27
#include<qinputdialog.h>
 
28
#include<qcheckbox.h>
 
29
#include"psicon.h"
 
30
#include"psiaccount.h"
 
31
#include"userlist.h"
 
32
#include"common.h"
 
33
#include"msgmle.h"
 
34
 
 
35
 
 
36
//----------------------------------------------------------------------------
 
37
// StatusShowDlg
 
38
//----------------------------------------------------------------------------
 
39
StatusShowDlg::StatusShowDlg(const UserListItem &u)
 
40
:QDialog(0, 0, false, WDestructiveClose)
 
41
{
 
42
        // build the dialog
 
43
        QVBoxLayout *vb = new QVBoxLayout(this, 8);
 
44
        PsiTextView *te = new PsiTextView(this);
 
45
        vb->addWidget(te);
 
46
        QHBoxLayout *hb = new QHBoxLayout(vb);
 
47
        QPushButton *pb = new QPushButton(tr("&Close"), this);
 
48
        connect(pb, SIGNAL(clicked()), SLOT(close()));
 
49
        hb->addStretch(1);
 
50
        hb->addWidget(pb);
 
51
        hb->addStretch(1);
 
52
 
 
53
        // set the rest up
 
54
        te->setReadOnly(true);
 
55
        te->setTextFormat(RichText);
 
56
        te->setText(u.makeDesc());
 
57
 
 
58
        setCaption(tr("Status for %1").arg(jidnick(u.jid().full(), u.name())));
 
59
        resize(400,240);
 
60
 
 
61
        pb->setFocus();
 
62
}
 
63
 
 
64
 
 
65
//----------------------------------------------------------------------------
 
66
// StatusSetDlg
 
67
//----------------------------------------------------------------------------
 
68
static int combomap[7] = { STATUS_CHAT, STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND, STATUS_INVISIBLE, STATUS_OFFLINE };
 
69
 
 
70
class StatusSetDlg::Private
 
71
{
 
72
public:
 
73
        Private() {}
 
74
 
 
75
        PsiCon *psi;
 
76
        PsiAccount *pa;
 
77
        Status s;
 
78
        ChatView *te;
 
79
        QComboBox *cb_type, *cb_preset;
 
80
        QCheckBox *save;
 
81
};
 
82
 
 
83
StatusSetDlg::StatusSetDlg(PsiCon *psi, const Status &s)
 
84
:QDialog(0, 0, false, WDestructiveClose)
 
85
{
 
86
        d = new Private;
 
87
        d->psi = psi;
 
88
        d->pa = 0;
 
89
        d->psi->dialogRegister(this);
 
90
        d->s = s;
 
91
 
 
92
        setCaption(CAP(tr("Set Status: All accounts")));
 
93
        init();
 
94
}
 
95
 
 
96
StatusSetDlg::StatusSetDlg(PsiAccount *pa, const Status &s)
 
97
:QDialog(0, 0, false, WDestructiveClose)
 
98
{
 
99
        d = new Private;
 
100
        d->psi = 0;
 
101
        d->pa = pa;
 
102
        d->pa->dialogRegister(this);
 
103
        d->s = s;
 
104
 
 
105
        setCaption(CAP(tr("Set Status: %1").arg(d->pa->name())));
 
106
        init();
 
107
}
 
108
 
 
109
void StatusSetDlg::init()
 
110
{
 
111
        int type = makeSTATUS(d->s);
 
112
 
 
113
        // build the dialog
 
114
        QVBoxLayout *vb = new QVBoxLayout(this, 8);
76
115
        QHBoxLayout *hb1 = new QHBoxLayout(vb);
77
116
 
78
117
        QLabel *l;
79
118
        l = new QLabel(tr("Status:"), this);
80
119
        hb1->addWidget(l);
81
 
        cb_type = new QComboBox(this);
 
120
        d->cb_type = new QComboBox(this);
82
121
        int n;
83
 
        for(n = 0; n < 4; ++n)
84
 
                cb_type->insertItem(status2txt(combomap[n]));
85
 
        for(n = 0; n < 4; ++n) {
86
 
                if(info->type == combomap[n]) {
87
 
                        cb_type->setCurrentItem(n);
 
122
        for(n = 0; n < 7; ++n)
 
123
                d->cb_type->insertItem(status2txt(combomap[n]));
 
124
        for(n = 0; n < 7; ++n) {
 
125
                if(type == combomap[n]) {
 
126
                        d->cb_type->setCurrentItem(n);
88
127
                        break;
89
128
                }
90
129
        }
91
 
        hb1->addWidget(cb_type,1);
 
130
        hb1->addWidget(d->cb_type,1);
92
131
        l = new QLabel(tr("Preset:"), this);
93
132
        hb1->addWidget(l);
94
 
        cb_preset = new QComboBox(this);
95
 
        cb_preset->insertItem(tr("<None>"));
96
 
        cb_preset->insertStringList(option.sp.varsToStringList());
97
 
        connect(cb_preset, SIGNAL(highlighted(int)), SLOT(chooseStatusPreset(int)));
98
 
        hb1->addWidget(cb_preset,1);
99
 
 
100
 
        te = new MsgMle(this);
101
 
        vb->addWidget(te);
102
 
        QHBoxLayout *hb = new QHBoxLayout(vb);
103
 
        QPushButton *pb1 = new QPushButton(tr("&Set"), this);
104
 
        QPushButton *pb2 = new QPushButton(tr("&Cancel"), this);
105
 
        pb1->setMinimumWidth(80);
106
 
        pb2->setMinimumWidth(80);
107
 
        hb->addWidget(pb1);
108
 
        hb->addStretch(1);
109
 
        hb->addWidget(pb2);
110
 
 
111
 
        // set the rest up
112
 
        te->setTextFormat(PlainText);
113
 
        te->setText(info->str);
114
 
        te->selectAll();
115
 
        connect(pb1, SIGNAL(clicked()), SLOT(doButton()));
116
 
        connect(pb2, SIGNAL(clicked()), SLOT(close()));
117
 
        te->setFocus();
118
 
 
119
 
        setCaption(CAP(tr("Set Status")));
120
 
 
121
 
        resize(400,240);
 
133
        d->cb_preset = new QComboBox(this);
 
134
        d->cb_preset->insertItem(tr("<None>"));
 
135
        QStringList presets=option.sp.varsToStringList();
 
136
        presets.sort();
 
137
        d->cb_preset->insertStringList(presets);
 
138
        connect(d->cb_preset, SIGNAL(highlighted(int)), SLOT(chooseStatusPreset(int)));
 
139
        hb1->addWidget(d->cb_preset,1);
 
140
 
 
141
        d->te = new ChatView(this);
 
142
        d->te->setReadOnly(false);
 
143
        d->te->setTextFormat(PlainText);
 
144
        d->te->setMinimumHeight(50);
 
145
        vb->addWidget(d->te);
 
146
        QHBoxLayout *hb = new QHBoxLayout(vb);
 
147
        QPushButton *pb1 = new QPushButton(tr("&Set"), this);
 
148
        QPushButton *pb2 = new QPushButton(tr("&Cancel"), this);
 
149
        d->save = new QCheckBox(this);
 
150
        d->save->setText(tr("Sa&ve as Preset"));
 
151
        d->save->setChecked(false);
 
152
        hb->addWidget(pb1);
 
153
        hb->addStretch(1);
 
154
        hb->addWidget(d->save);
 
155
        hb->addStretch(1);
 
156
        hb->addWidget(pb2);
 
157
 
 
158
        // set the rest up
 
159
        d->te->setTextFormat(PlainText);
 
160
        d->te->setText(d->s.status());
 
161
        d->te->selectAll();
 
162
        connect(pb1, SIGNAL(clicked()), SLOT(doButton()));
 
163
        connect(pb2, SIGNAL(clicked()), SLOT(cancel()));
 
164
        d->te->setFocus();
 
165
 
 
166
        resize(400,240);
 
167
}
 
168
 
 
169
StatusSetDlg::~StatusSetDlg()
 
170
{
 
171
        if(d->psi)
 
172
                d->psi->dialogUnregister(this);
 
173
        else if(d->pa)
 
174
                d->pa->dialogUnregister(this);
 
175
        delete d;
 
176
}
 
177
 
 
178
void StatusSetDlg::keyPressEvent(QKeyEvent *e)
 
179
{
 
180
        if(e->key() == Key_Escape)
 
181
                close();
 
182
        else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
 
183
                doButton();
 
184
        else
 
185
                e->ignore();
122
186
}
123
187
 
124
188
void StatusSetDlg::doButton()
125
189
{
126
 
        info->type = combomap[cb_type->currentItem()];
127
 
        info->str = te->text();
128
 
        accept();
 
190
        // Save preset
 
191
        if (d->save->isChecked()) {
 
192
                QString text;
 
193
                while(1) {
 
194
                        // Get preset
 
195
                        bool ok = FALSE;
 
196
                        text = QInputDialog::getText(
 
197
                                CAP(tr("New Status Preset")),
 
198
                                        tr("Please enter a name for the new status preset:"),
 
199
                                        QLineEdit::Normal, text, &ok, this);
 
200
                        if (!ok)
 
201
                                return;
 
202
                        
 
203
                        // Check preset name
 
204
                        if (text.isEmpty()) {
 
205
                                QMessageBox::information(this, tr("Error"), 
 
206
                                        tr("Can't create a blank preset!"));
 
207
                        }
 
208
                        else if(option.sp.findByKey(text) != option.sp.end()) {
 
209
                                QMessageBox::information(this, tr("Error"), 
 
210
                                        tr("You already have a preset with that name!"));
 
211
                        }
 
212
                        else 
 
213
                                break;
 
214
                }
 
215
                // Store preset
 
216
                option.sp.set(text,d->te->text());
 
217
        } 
 
218
 
 
219
        // Set status
 
220
        int type = combomap[d->cb_type->currentItem()];
 
221
        QString str = d->te->text();
 
222
 
 
223
        set(makeStatus(type, str));
 
224
        close();
129
225
}
130
226
 
131
227
void StatusSetDlg::chooseStatusPreset(int x)
133
229
        if(x < 1)
134
230
                return;
135
231
 
136
 
        te->setText(option.sp.get(cb_preset->text(x)));
137
 
}
138
 
 
139
 
/* static */ bool StatusSetDlg::getStatus(StatusInfo *x_info)
140
 
{
141
 
        StatusSetDlg *w = new StatusSetDlg(x_info);
142
 
        bool ok;
143
 
 
144
 
        ok = (w->exec() == Accepted) ? TRUE: FALSE;
145
 
 
146
 
        delete w;
147
 
        return ok;
 
232
        d->te->setText(option.sp.get(d->cb_preset->text(x)));
 
233
}
 
234
 
 
235
void StatusSetDlg::cancel()
 
236
{
 
237
        emit cancelled();
 
238
        close();
 
239
}
 
240
 
 
241
void StatusSetDlg::reject()
 
242
{
 
243
        cancel();
 
244
        QDialog::reject();
148
245
}