No longer honours following status in JSON, instead relies solely on following list.
[larjonas-pumpa.git] / src / pumpasettingsdialog.cpp
blob43c5ee376df2dc56016451eb5dc28fed84accf39
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "pumpasettingsdialog.h"
21 #include "util.h"
22 #include "pumpa_defines.h"
24 //------------------------------------------------------------------------------
26 PumpaSettingsDialog::PumpaSettingsDialog(PumpaSettings* settings,
27 QWidget* parent):
28 QDialog(parent),
29 s(settings)
31 m_layout = new QVBoxLayout;
33 // Account
34 QGroupBox* accountGroupBox = new QGroupBox(tr("Account"));
35 QVBoxLayout* accountLayout = new QVBoxLayout;
37 m_currentAccountLabel = new QLabel(tr("Not logged in currently."), this);
38 accountLayout->addWidget(m_currentAccountLabel);
40 m_authButton = new QPushButton(tr("Change account"), this);
41 connect(m_authButton, SIGNAL(clicked()), this, SLOT(onAuthButtonClicked()));
42 accountLayout->addWidget(m_authButton);
44 QLabel* acctInfoLabel =
45 new QLabel(tr("Clicking \"Change account\" will run the "
46 "authentication setup again for a new pump.io "
47 "account. This will remove the current login "
48 "credentials since Pumpa only supports one "
49 "account at a time."));
50 acctInfoLabel->setWordWrap(true);
51 accountLayout->addWidget(acctInfoLabel);
53 accountGroupBox->setLayout(accountLayout);
55 // User interface
56 QGroupBox* uiGroupBox = new QGroupBox(tr("Interface"));
57 QFormLayout* uiLayout = new QFormLayout;
59 m_updateTimeSpinBox = new QSpinBox(this);
60 m_updateTimeSpinBox->setMinimum(1);
61 m_updateTimeSpinBox->setMaximum(30);
63 uiLayout->addRow(tr("Update interval (in minutes):"),
64 m_updateTimeSpinBox);
66 QStringList addressItems;
67 addressItems << ""
68 << tr("Public")
69 << tr("Followers");
71 m_defaultToComboBox = new QComboBox(this);
72 m_defaultToComboBox->addItems(addressItems);
73 uiLayout->addRow(tr("Default \"To\":"), m_defaultToComboBox);
75 m_defaultCcComboBox = new QComboBox(this);
76 m_defaultCcComboBox->addItems(addressItems);
77 uiLayout->addRow(tr("Default \"CC\":"), m_defaultCcComboBox);
79 m_useIconCheckBox = new QCheckBox(tr("Use icon in system tray"), this);
80 uiLayout->addRow(m_useIconCheckBox);
82 m_showCharCountCheckBox = new QCheckBox(tr("Show message character count"), this);
83 uiLayout->addRow(m_showCharCountCheckBox);
85 uiGroupBox->setLayout(uiLayout);
87 // Notifications
88 QGroupBox* notifyGroupBox = new QGroupBox(tr("Notifications"));
89 QFormLayout* notifyLayout = new QFormLayout;
91 QStringList timelineList;
92 timelineList << tr("Never")
93 << tr("Direct only")
94 << tr("Direct or mention")
95 << tr("Direct, mention or inbox")
96 << tr("Anything");
98 m_highlightComboBox = new QComboBox(this);
99 m_highlightComboBox->addItems(timelineList);
100 notifyLayout->addRow(tr("Highlight tray icon on:"), m_highlightComboBox);
102 m_popupComboBox = new QComboBox(this);
103 m_popupComboBox->addItems(timelineList);
104 notifyLayout->addRow(tr("Popup notification on:"), m_popupComboBox);
106 notifyGroupBox->setLayout(notifyLayout);
108 m_buttonBox = new QDialogButtonBox(this);
109 m_buttonBox->setOrientation(Qt::Horizontal);
110 m_buttonBox->setStandardButtons(QDialogButtonBox::Ok);
111 connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
112 connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(onOKClicked()));
113 connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
115 // Dialog layout
116 m_layout->addWidget(uiGroupBox);
117 m_layout->addWidget(notifyGroupBox);
118 m_layout->addWidget(accountGroupBox);
119 m_layout->addWidget(m_buttonBox);
121 setLayout(m_layout);
124 //------------------------------------------------------------------------------
126 void PumpaSettingsDialog::onAuthButtonClicked() {
127 accept();
128 emit newAccount();
131 //------------------------------------------------------------------------------
133 void PumpaSettingsDialog::setVisible(bool visible) {
134 if (visible)
135 updateUI();
136 QDialog::setVisible(visible);
139 //------------------------------------------------------------------------------
141 int PumpaSettingsDialog::comboIndexConverter(int ci, bool backwards) {
142 static QList<int> comboToFeeds;
143 if (comboToFeeds.isEmpty()) {
144 comboToFeeds << 0
145 << FEED_DIRECT
146 << (FEED_DIRECT | FEED_MENTIONS)
147 << (FEED_DIRECT | FEED_MENTIONS | FEED_INBOX)
148 << (FEED_DIRECT | FEED_MENTIONS | FEED_INBOX | FEED_MEANWHILE);
151 if (backwards) {
152 int ret = comboToFeeds.indexOf(ci);
153 return ret == -1 ? 0 : ret;
156 return ci < comboToFeeds.size() ? comboToFeeds[ci] : 0;
159 //------------------------------------------------------------------------------
161 void PumpaSettingsDialog::updateUI() {
162 QString accountId = siteUrlToAccountId(s->userName(), s->siteUrl());
163 m_currentAccountLabel->setText(QString(tr("Currently logged in as %1.")).
164 arg(accountId));
166 m_updateTimeSpinBox->setValue(s->reloadTime());
168 m_useIconCheckBox->setChecked(s->useTrayIcon());
169 m_showCharCountCheckBox->setChecked(s->showCharCount());
171 m_highlightComboBox->
172 setCurrentIndex(feedIntToComboIndex(s->highlightFeeds()));
174 m_popupComboBox->
175 setCurrentIndex(feedIntToComboIndex(s->popupFeeds()));
177 m_defaultToComboBox->setCurrentIndex(s->defaultToAddress());
178 m_defaultCcComboBox->setCurrentIndex(s->defaultCcAddress());
181 //------------------------------------------------------------------------------
183 void PumpaSettingsDialog::onOKClicked() {
184 s->reloadTime(m_updateTimeSpinBox->value());
185 s->useTrayIcon(m_useIconCheckBox->isChecked());
186 s->showCharCount(m_showCharCountCheckBox->isChecked());
188 s->highlightFeeds(comboIndexToFeedInt(m_highlightComboBox->currentIndex()));
189 s->popupFeeds(comboIndexToFeedInt(m_popupComboBox->currentIndex()));
191 s->defaultToAddress(m_defaultToComboBox->currentIndex());
192 s->defaultCcAddress(m_defaultCcComboBox->currentIndex());
193 emit accepted();