| 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 |
|
|---|
| 21 | #include"statusdlg.h"
|
|---|
| 22 |
|
|---|
| 23 | #include<qpushbutton.h>
|
|---|
| 24 | #include<qlayout.h>
|
|---|
| 25 | #include<qlabel.h>
|
|---|
| 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 | // FIXME: Will no longer be needed once it is out of the groupchat contactview
|
|---|
| 39 | //----------------------------------------------------------------------------
|
|---|
| 40 | StatusShowDlg::StatusShowDlg(const UserListItem &u)
|
|---|
| 41 | :QDialog(0, 0, false, WDestructiveClose)
|
|---|
| 42 | {
|
|---|
| 43 | // build the dialog
|
|---|
| 44 | QVBoxLayout *vb = new QVBoxLayout(this, 8);
|
|---|
| 45 | PsiTextView *te = new PsiTextView(this);
|
|---|
| 46 | vb->addWidget(te);
|
|---|
| 47 | QHBoxLayout *hb = new QHBoxLayout(vb);
|
|---|
| 48 | QPushButton *pb = new QPushButton(tr("&Close"), this);
|
|---|
| 49 | connect(pb, SIGNAL(clicked()), SLOT(close()));
|
|---|
| 50 | hb->addStretch(1);
|
|---|
| 51 | hb->addWidget(pb);
|
|---|
| 52 | hb->addStretch(1);
|
|---|
| 53 |
|
|---|
| 54 | // set the rest up
|
|---|
| 55 | te->setReadOnly(true);
|
|---|
| 56 | te->setTextFormat(RichText);
|
|---|
| 57 | te->setText(u.makeDesc());
|
|---|
| 58 |
|
|---|
| 59 | setCaption(tr("Status for %1").arg(jidnick(u.jid().full(), u.name())));
|
|---|
| 60 | resize(400,240);
|
|---|
| 61 |
|
|---|
| 62 | pb->setFocus();
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 | //----------------------------------------------------------------------------
|
|---|
| 67 | // StatusSetDlg
|
|---|
| 68 | //----------------------------------------------------------------------------
|
|---|
| 69 | static int combomap[7] = { STATUS_CHAT, STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND, STATUS_INVISIBLE, STATUS_OFFLINE };
|
|---|
| 70 |
|
|---|
| 71 | class StatusSetDlg::Private
|
|---|
| 72 | {
|
|---|
| 73 | public:
|
|---|
| 74 | Private() {}
|
|---|
| 75 |
|
|---|
| 76 | PsiCon *psi;
|
|---|
| 77 | PsiAccount *pa;
|
|---|
| 78 | Status s;
|
|---|
| 79 | ChatView *te;
|
|---|
| 80 | QComboBox *cb_type, *cb_preset;
|
|---|
| 81 | QCheckBox *save;
|
|---|
| 82 | };
|
|---|
| 83 |
|
|---|
| 84 | StatusSetDlg::StatusSetDlg(PsiCon *psi, const Status &s)
|
|---|
| 85 | :QDialog(0, 0, false, WDestructiveClose)
|
|---|
| 86 | {
|
|---|
| 87 | d = new Private;
|
|---|
| 88 | d->psi = psi;
|
|---|
| 89 | d->pa = 0;
|
|---|
| 90 | d->psi->dialogRegister(this);
|
|---|
| 91 | d->s = s;
|
|---|
| 92 |
|
|---|
| 93 | setCaption(CAP(tr("Set Status: All accounts")));
|
|---|
| 94 | init();
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | StatusSetDlg::StatusSetDlg(PsiAccount *pa, const Status &s)
|
|---|
| 98 | :QDialog(0, 0, false, WDestructiveClose)
|
|---|
| 99 | {
|
|---|
| 100 | d = new Private;
|
|---|
| 101 | d->psi = 0;
|
|---|
| 102 | d->pa = pa;
|
|---|
| 103 | d->pa->dialogRegister(this);
|
|---|
| 104 | d->s = s;
|
|---|
| 105 |
|
|---|
| 106 | setCaption(CAP(tr("Set Status: %1").arg(d->pa->name())));
|
|---|
| 107 | init();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | void StatusSetDlg::init()
|
|---|
| 111 | {
|
|---|
| 112 | int type = makeSTATUS(d->s);
|
|---|
| 113 |
|
|---|
| 114 | // build the dialog
|
|---|
| 115 | QVBoxLayout *vb = new QVBoxLayout(this, 8);
|
|---|
| 116 | QHBoxLayout *hb1 = new QHBoxLayout(vb);
|
|---|
| 117 |
|
|---|
| 118 | QLabel *l;
|
|---|
| 119 | l = new QLabel(tr("Status:"), this);
|
|---|
| 120 | hb1->addWidget(l);
|
|---|
| 121 | d->cb_type = new QComboBox(this);
|
|---|
| 122 | int n;
|
|---|
| 123 | for(n = 0; n < 7; ++n)
|
|---|
| 124 | d->cb_type->insertItem(status2txt(combomap[n]));
|
|---|
| 125 | for(n = 0; n < 7; ++n) {
|
|---|
| 126 | if(type == combomap[n]) {
|
|---|
| 127 | d->cb_type->setCurrentItem(n);
|
|---|
| 128 | break;
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | hb1->addWidget(d->cb_type,1);
|
|---|
| 132 | l = new QLabel(tr("Preset:"), this);
|
|---|
| 133 | hb1->addWidget(l);
|
|---|
| 134 | d->cb_preset = new QComboBox(this);
|
|---|
| 135 | d->cb_preset->insertItem(tr("<None>"));
|
|---|
| 136 | QStringList presets=option.sp.varsToStringList();
|
|---|
| 137 | presets.sort();
|
|---|
| 138 | d->cb_preset->insertStringList(presets);
|
|---|
| 139 | connect(d->cb_preset, SIGNAL(highlighted(int)), SLOT(chooseStatusPreset(int)));
|
|---|
| 140 | hb1->addWidget(d->cb_preset,1);
|
|---|
| 141 |
|
|---|
| 142 | d->te = new ChatView(this);
|
|---|
| 143 | d->te->setReadOnly(false);
|
|---|
| 144 | d->te->setTextFormat(PlainText);
|
|---|
| 145 | d->te->setMinimumHeight(50);
|
|---|
| 146 | vb->addWidget(d->te);
|
|---|
| 147 | QHBoxLayout *hb = new QHBoxLayout(vb);
|
|---|
| 148 | QPushButton *pb1 = new QPushButton(tr("&Set"), this);
|
|---|
| 149 | QPushButton *pb2 = new QPushButton(tr("&Cancel"), this);
|
|---|
| 150 | d->save = new QCheckBox(this);
|
|---|
| 151 | d->save->setText(tr("Sa&ve as Preset"));
|
|---|
| 152 | d->save->setChecked(false);
|
|---|
| 153 | hb->addWidget(pb1);
|
|---|
| 154 | hb->addStretch(1);
|
|---|
| 155 | hb->addWidget(d->save);
|
|---|
| 156 | hb->addStretch(1);
|
|---|
| 157 | hb->addWidget(pb2);
|
|---|
| 158 |
|
|---|
| 159 | // set the rest up
|
|---|
| 160 | d->te->setTextFormat(PlainText);
|
|---|
| 161 | d->te->setText(d->s.status());
|
|---|
| 162 | d->te->selectAll();
|
|---|
| 163 | connect(pb1, SIGNAL(clicked()), SLOT(doButton()));
|
|---|
| 164 | connect(pb2, SIGNAL(clicked()), SLOT(cancel()));
|
|---|
| 165 | d->te->setFocus();
|
|---|
| 166 |
|
|---|
| 167 | resize(400,240);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | StatusSetDlg::~StatusSetDlg()
|
|---|
| 171 | {
|
|---|
| 172 | if(d->psi)
|
|---|
| 173 | d->psi->dialogUnregister(this);
|
|---|
| 174 | else if(d->pa)
|
|---|
| 175 | d->pa->dialogUnregister(this);
|
|---|
| 176 | delete d;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | void StatusSetDlg::keyPressEvent(QKeyEvent *e)
|
|---|
| 180 | {
|
|---|
| 181 | if(e->key() == Key_Escape)
|
|---|
| 182 | close();
|
|---|
| 183 | else if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
|
|---|
| 184 | doButton();
|
|---|
| 185 | else
|
|---|
| 186 | e->ignore();
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | void StatusSetDlg::doButton()
|
|---|
| 190 | {
|
|---|
| 191 | // Save preset
|
|---|
| 192 | if (d->save->isChecked()) {
|
|---|
| 193 | QString text;
|
|---|
| 194 | while(1) {
|
|---|
| 195 | // Get preset
|
|---|
| 196 | bool ok = FALSE;
|
|---|
| 197 | text = QInputDialog::getText(
|
|---|
| 198 | CAP(tr("New Status Preset")),
|
|---|
| 199 | tr("Please enter a name for the new status preset:"),
|
|---|
| 200 | QLineEdit::Normal, text, &ok, this);
|
|---|
| 201 | if (!ok)
|
|---|
| 202 | return;
|
|---|
| 203 |
|
|---|
| 204 | // Check preset name
|
|---|
| 205 | if (text.isEmpty()) {
|
|---|
| 206 | QMessageBox::information(this, tr("Error"),
|
|---|
| 207 | tr("Can't create a blank preset!"));
|
|---|
| 208 | }
|
|---|
| 209 | else if(option.sp.findByKey(text) != option.sp.end()) {
|
|---|
| 210 | QMessageBox::information(this, tr("Error"),
|
|---|
| 211 | tr("You already have a preset with that name!"));
|
|---|
| 212 | }
|
|---|
| 213 | else
|
|---|
| 214 | break;
|
|---|
| 215 | }
|
|---|
| 216 | // Store preset
|
|---|
| 217 | option.sp.set(text,d->te->text());
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | // Set status
|
|---|
| 221 | int type = combomap[d->cb_type->currentItem()];
|
|---|
| 222 | QString str = d->te->text();
|
|---|
| 223 |
|
|---|
| 224 | set(makeStatus(type, str));
|
|---|
| 225 | close();
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | void StatusSetDlg::chooseStatusPreset(int x)
|
|---|
| 229 | {
|
|---|
| 230 | if(x < 1)
|
|---|
| 231 | return;
|
|---|
| 232 |
|
|---|
| 233 | d->te->setText(option.sp.get(d->cb_preset->text(x)));
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | void StatusSetDlg::cancel()
|
|---|
| 237 | {
|
|---|
| 238 | emit cancelled();
|
|---|
| 239 | close();
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | void StatusSetDlg::reject()
|
|---|
| 243 | {
|
|---|
| 244 | cancel();
|
|---|
| 245 | QDialog::reject();
|
|---|
| 246 | }
|
|---|