2
* statuscombobox.cpp - helper class that displays available statuses using QComboBox
3
* Copyright (C) 2008 Maciej Niedzielski
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
#include "statuscombobox.h"
23
#include "psioptions.h"
27
* \brief Constructs new StatusComboBox
28
* \param parent, widget's parent
29
* \param type, selected status type just after creation
31
StatusComboBox::StatusComboBox(QWidget* parent, XMPP::Status::Type type)
34
if (PsiOptions::instance()->getOption("options.ui.menu.status.chat").toBool()) {
35
addStatus(XMPP::Status::FFC);
37
addStatus(XMPP::Status::Online);
38
addStatus(XMPP::Status::Away);
39
if (PsiOptions::instance()->getOption("options.ui.menu.status.xa").toBool()) {
40
addStatus(XMPP::Status::XA);
42
addStatus(XMPP::Status::DND);
43
if (PsiOptions::instance()->getOption("options.ui.menu.status.invisible").toBool()) {
44
addStatus(XMPP::Status::Invisible);
46
addStatus(XMPP::Status::Offline);
48
connect(this, SIGNAL(currentIndexChanged(int)), SLOT(onCurrentIndexChanged(int)));
54
* \brief Set currently selected status
56
void StatusComboBox::setStatus(XMPP::Status::Type type)
58
if (type == XMPP::Status::FFC && !PsiOptions::instance()->getOption("options.ui.menu.status.chat").toBool())
59
type = XMPP::Status::Online;
60
else if (type == XMPP::Status::XA && !PsiOptions::instance()->getOption("options.ui.menu.status.xa").toBool())
61
type = XMPP::Status::Away;
62
else if (type == XMPP::Status::Invisible && !PsiOptions::instance()->getOption("options.ui.menu.status.invisible").toBool())
63
type = XMPP::Status::Offline;
65
for (int i = 0; i < count(); ++i) {
66
if (static_cast<XMPP::Status::Type>(itemData(i).toInt()) == type) {
74
* \brief Read currently selected status
76
XMPP::Status::Type StatusComboBox::status() const
78
return static_cast<XMPP::Status::Type>(itemData(currentIndex()).toInt());
83
void StatusComboBox::addStatus(XMPP::Status::Type status){
84
addItem(status2txt(status), status);
87
void StatusComboBox::onCurrentIndexChanged(int index)
89
emit statusChanged(static_cast<XMPP::Status::Type>(itemData(index).toInt()));