1
/****************************************************************************
2
** statusdlg.cpp - dialog for setting and reading status messages
3
** Copyright (C) 2001, 2002 Justin Karneges
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.
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.
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.
19
****************************************************************************/
2
* statusdlg.cpp - dialogs for setting and reading status messages
3
* Copyright (C) 2001, 2002 Justin Karneges
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.
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.
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
21
21
#include"statusdlg.h"
23
23
#include<qpushbutton.h>
24
24
#include<qlayout.h>
28
StatusShowDlg::StatusShowDlg(UserListItem *i)
29
:QDialog(0,0,FALSE,WDestructiveClose)
32
QVBoxLayout *vb = new QVBoxLayout(this, 8);
33
MsgMle *te = new MsgMle(this);
35
QHBoxLayout *hb = new QHBoxLayout(vb);
36
QPushButton *pb = new QPushButton(tr("&Close"), this);
37
pb->setMinimumWidth(80);
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()));
56
setCaption(QString(tr("Status for %1")).arg(nick));
61
void StatusShowDlg::aOpenURL(const QString &url)
67
static int combomap[4] = { STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND };
69
StatusSetDlg::StatusSetDlg(StatusInfo *x_info)
75
QVBoxLayout *vb = new QVBoxLayout(this, 8);
27
#include<qinputdialog.h>
30
#include"psiaccount.h"
36
//----------------------------------------------------------------------------
38
//----------------------------------------------------------------------------
39
StatusShowDlg::StatusShowDlg(const UserListItem &u)
40
:QDialog(0, 0, false, WDestructiveClose)
43
QVBoxLayout *vb = new QVBoxLayout(this, 8);
44
PsiTextView *te = new PsiTextView(this);
46
QHBoxLayout *hb = new QHBoxLayout(vb);
47
QPushButton *pb = new QPushButton(tr("&Close"), this);
48
connect(pb, SIGNAL(clicked()), SLOT(close()));
54
te->setReadOnly(true);
55
te->setTextFormat(RichText);
56
te->setText(u.makeDesc());
58
setCaption(tr("Status for %1").arg(jidnick(u.jid().full(), u.name())));
65
//----------------------------------------------------------------------------
67
//----------------------------------------------------------------------------
68
static int combomap[7] = { STATUS_CHAT, STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND, STATUS_INVISIBLE, STATUS_OFFLINE };
70
class StatusSetDlg::Private
79
QComboBox *cb_type, *cb_preset;
83
StatusSetDlg::StatusSetDlg(PsiCon *psi, const Status &s)
84
:QDialog(0, 0, false, WDestructiveClose)
89
d->psi->dialogRegister(this);
92
setCaption(CAP(tr("Set Status: All accounts")));
96
StatusSetDlg::StatusSetDlg(PsiAccount *pa, const Status &s)
97
:QDialog(0, 0, false, WDestructiveClose)
102
d->pa->dialogRegister(this);
105
setCaption(CAP(tr("Set Status: %1").arg(d->pa->name())));
109
void StatusSetDlg::init()
111
int type = makeSTATUS(d->s);
114
QVBoxLayout *vb = new QVBoxLayout(this, 8);
76
115
QHBoxLayout *hb1 = new QHBoxLayout(vb);
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);
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);
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);
100
te = new MsgMle(this);
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);
112
te->setTextFormat(PlainText);
113
te->setText(info->str);
115
connect(pb1, SIGNAL(clicked()), SLOT(doButton()));
116
connect(pb2, SIGNAL(clicked()), SLOT(close()));
119
setCaption(CAP(tr("Set Status")));
133
d->cb_preset = new QComboBox(this);
134
d->cb_preset->insertItem(tr("<None>"));
135
QStringList presets=option.sp.varsToStringList();
137
d->cb_preset->insertStringList(presets);
138
connect(d->cb_preset, SIGNAL(highlighted(int)), SLOT(chooseStatusPreset(int)));
139
hb1->addWidget(d->cb_preset,1);
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);
154
hb->addWidget(d->save);
159
d->te->setTextFormat(PlainText);
160
d->te->setText(d->s.status());
162
connect(pb1, SIGNAL(clicked()), SLOT(doButton()));
163
connect(pb2, SIGNAL(clicked()), SLOT(cancel()));
169
StatusSetDlg::~StatusSetDlg()
172
d->psi->dialogUnregister(this);
174
d->pa->dialogUnregister(this);
178
void StatusSetDlg::keyPressEvent(QKeyEvent *e)
180
if(e->key() == Key_Escape)
182
else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
124
188
void StatusSetDlg::doButton()
126
info->type = combomap[cb_type->currentItem()];
127
info->str = te->text();
191
if (d->save->isChecked()) {
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);
204
if (text.isEmpty()) {
205
QMessageBox::information(this, tr("Error"),
206
tr("Can't create a blank preset!"));
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!"));
216
option.sp.set(text,d->te->text());
220
int type = combomap[d->cb_type->currentItem()];
221
QString str = d->te->text();
223
set(makeStatus(type, str));
131
227
void StatusSetDlg::chooseStatusPreset(int x)