PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/schat/settingsdialog.cpp

http://schat.googlecode.com/
C++ | 1255 lines | 947 code | 253 blank | 55 comment | 90 complexity | a173ac45d6082ed7a3b75c29da9c2d4d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. /* $Id: settingsdialog.cpp 1522 2011-07-14 05:22:11Z IMPOMEZIA $
  2. * IMPOMEZIA Simple Chat
  3. * Copyright Š 2008-2011 IMPOMEZIA <schat@impomezia.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (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, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <QCheckBox>
  19. #include <QComboBox>
  20. #include <QCompleter>
  21. #include <QDesktopServices>
  22. #include <QDir>
  23. #include <QFile>
  24. #include <QGridLayout>
  25. #include <QGroupBox>
  26. #include <QLabel>
  27. #include <QLineEdit>
  28. #include <QProcess>
  29. #include <QPushButton>
  30. #include <QSound>
  31. #include <QSpinBox>
  32. #include <QStyleFactory>
  33. #include <QTextStream>
  34. #include "abstractprofile.h"
  35. #include "emoticons/emoticons.h"
  36. #include "languagebox.h"
  37. #include "profilewidget.h"
  38. #include "settings.h"
  39. #include "settingsdialog.h"
  40. #include "simplechatapp.h"
  41. #include "translation.h"
  42. #include "widget/networkwidget.h"
  43. #include "widget/nickedit.h"
  44. #include "widget/soundwidget.h"
  45. #ifndef SCHAT_NO_WEBKIT
  46. #include "chatwindow/chatwindowstyle.h"
  47. #endif
  48. /*!
  49. * \brief ??????????? ?????? SettingsDialog.
  50. */
  51. SettingsDialog::SettingsDialog(QWidget *parent)
  52. : AbstractSettingsDialog(parent)
  53. {
  54. ProfileSettings *profilePage = new ProfileSettings(this);
  55. NetworkSettings *networkPage = new NetworkSettings(this);
  56. createPage(QIcon(":/images/profile.png"), tr("Personal data"), profilePage);
  57. createPage(QIcon(":/images/network.png"), tr("Network"), networkPage);
  58. createPage(QIcon(":/images/applications-graphics.png"), tr("Interface"), new InterfaceSettings(this));
  59. createPage(QIcon(":/images/emoticon.png"), tr("Emoticons"), new EmoticonsSettings(this));
  60. createPage(QIcon(":/images/sound.png"), tr("Sounds"), new SoundSettings(this));
  61. createPage(QIcon(":/images/notification.png"), tr("Notifications"), new NotificationSettings(this));
  62. createPage(QIcon(":/images/statuses.png"), tr("Statuses"), new StatusesSettings(this));
  63. createPage(QIcon(":/images/application-x-desktop.png"), tr("Others"), new MiscSettings(this));
  64. connect(profilePage, SIGNAL(validNick(bool)), m_okButton, SLOT(setEnabled(bool)));
  65. connect(networkPage, SIGNAL(validServer(bool)), m_okButton, SLOT(setEnabled(bool)));
  66. }
  67. /*!
  68. * ????????? ?????, ??????? ??? ????????????? ????? ???????.
  69. */
  70. void SettingsDialog::openFolder(int path)
  71. {
  72. QString dir = SimpleSettings->path(static_cast<Settings::Paths>(path)).at(0);
  73. if (!QDir().exists(dir))
  74. QDir().mkpath(dir);
  75. QDesktopServices::openUrl(QUrl::fromLocalFile(dir));
  76. }
  77. void SettingsDialog::accept()
  78. {
  79. emit save();
  80. SimpleSettings->write();
  81. close();
  82. }
  83. class ProfileSettings::Private
  84. {
  85. public:
  86. Private()
  87. : profile(SimpleSettings->profile()),
  88. maxRecentItems(SimpleSettings->getInt("Profile/MaxRecentItems"))
  89. {}
  90. AbstractProfile *profile;
  91. bool maxRecentItems;
  92. ProfileWidget *profileWidget;
  93. QLineEdit *byeMsgEdit;
  94. };
  95. /*!
  96. * \brief ??????????? ?????? ProfileSettings.
  97. */
  98. ProfileSettings::ProfileSettings(QWidget *parent)
  99. : AbstractSettingsPage(SettingsDialog::ProfilePage, parent), d(new Private)
  100. {
  101. d->profileWidget = new ProfileWidget(SimpleSettings->getBool("CompactGenderWidget"), this);
  102. connect(d->profileWidget, SIGNAL(validNick(bool)), SIGNAL(validNick(bool)));
  103. d->byeMsgEdit = new QLineEdit(d->profile->byeMsg(), this);
  104. d->byeMsgEdit->setMaxLength(AbstractProfile::MaxByeMsgLength);
  105. d->byeMsgEdit->setToolTip(tr("The message is seen by the other users if you are left of the chat"));
  106. if (d->maxRecentItems) {
  107. d->byeMsgEdit->setCompleter(new QCompleter(SimpleSettings->getList("Profile/RecentByeMsgs"), this));
  108. d->byeMsgEdit->completer()->setCaseSensitivity(Qt::CaseInsensitive);
  109. }
  110. QLabel *byeMsgLabel = new QLabel(tr("Message at the exit:"), this);
  111. byeMsgLabel->setBuddy(d->byeMsgEdit);
  112. QGroupBox *profileGroup = new QGroupBox(tr("Profile"), this);
  113. QVBoxLayout *profileLay = new QVBoxLayout(profileGroup);
  114. profileLay->setMargin(6);
  115. profileLay->setSpacing(4);
  116. profileLay->addWidget(d->profileWidget);
  117. profileLay->addWidget(byeMsgLabel);
  118. profileLay->addWidget(d->byeMsgEdit);
  119. QVBoxLayout *mainLay = new QVBoxLayout(this);
  120. mainLay->addWidget(profileGroup);
  121. mainLay->addStretch();
  122. mainLay->setContentsMargins(3, 3, 3, 0);
  123. }
  124. ProfileSettings::~ProfileSettings() { delete d; }
  125. void ProfileSettings::reset(int page)
  126. {
  127. if (page == m_id) {
  128. d->profileWidget->reset();
  129. d->byeMsgEdit->setText("");
  130. }
  131. }
  132. void ProfileSettings::save()
  133. {
  134. d->profileWidget->save();
  135. if (d->profile->byeMsg() != d->byeMsgEdit->text()) {
  136. d->profile->setByeMsg(d->byeMsgEdit->text());
  137. if (d->maxRecentItems)
  138. NickEdit::modifyRecentList("Profile/RecentByeMsgs", d->profile->byeMsg());
  139. SimpleSettings->notify(Settings::ByeMsgChanged);
  140. }
  141. }
  142. class NetworkSettings::Private
  143. {
  144. public:
  145. Private() {}
  146. NetworkWidget *network;
  147. QCheckBox *welcome;
  148. QComboBox *type;
  149. QGroupBox *proxyGroup;
  150. QLineEdit *host;
  151. QLineEdit *password;
  152. QLineEdit *userName;
  153. QSpinBox *port;
  154. };
  155. /*!
  156. * \brief ??????????? ?????? NetworkSettings.
  157. */
  158. NetworkSettings::NetworkSettings(QWidget *parent)
  159. : AbstractSettingsPage(SettingsDialog::NetworkPage, parent), d(new Private)
  160. {
  161. d->welcome = new QCheckBox(tr("Always use this connection"), this);
  162. d->welcome->setChecked(SimpleSettings->getBool("HideWelcome"));
  163. d->welcome->setToolTip(tr("Do not require personal information and server address at startup"));
  164. d->network = new NetworkWidget(this);
  165. connect(d->network, SIGNAL(validServer(bool)), SIGNAL(validServer(bool)));
  166. QGroupBox *serverGroup = new QGroupBox(tr("Connection"), this);
  167. QVBoxLayout *serverLay = new QVBoxLayout(serverGroup);
  168. serverLay->addWidget(d->network);
  169. serverLay->addWidget(d->welcome);
  170. serverLay->setMargin(6);
  171. serverLay->setSpacing(4);
  172. d->proxyGroup = new QGroupBox(tr("Connection via proxy server"), this);
  173. d->proxyGroup->setCheckable(true);
  174. d->proxyGroup->setChecked(SimpleSettings->getBool("Proxy/Enable"));
  175. d->proxyGroup->setVisible(!SimpleSettings->getBool("Proxy/HideAndDisable"));
  176. d->type = new QComboBox(this);
  177. d->type->addItem("HTTP");
  178. d->type->addItem("SOCKS5");
  179. d->type->setToolTip(tr("Proxy server type"));
  180. if (SimpleSettings->getInt("Proxy/Type") == 1)
  181. d->type->setCurrentIndex(1);
  182. else
  183. d->type->setCurrentIndex(0);
  184. QLabel *type = new QLabel(tr("&Type:"), this);
  185. type->setBuddy(d->type);
  186. d->host = new QLineEdit(SimpleSettings->getString("Proxy/Host"), this);
  187. d->host->setToolTip(tr("Proxy server address"));
  188. QLabel *host = new QLabel(tr("&Address:"), this);
  189. host->setBuddy(d->host);
  190. d->port = new QSpinBox(this);
  191. d->port->setRange(1, 65536);
  192. d->port->setToolTip(tr("Proxy server port"));
  193. d->port->setValue(SimpleSettings->getInt("Proxy/Port"));
  194. QLabel *port = new QLabel(tr("&Port:"), this);
  195. port->setBuddy(d->port);
  196. d->userName = new QLineEdit(SimpleSettings->getString("Proxy/UserName"), this);
  197. d->userName->setToolTip(tr("User name for authorization at proxy server"));
  198. QLabel *userName = new QLabel(tr("&Name:"), this);
  199. userName->setBuddy(d->userName);
  200. d->password = new QLineEdit(SimpleSettings->getString("Proxy/Password"), this);
  201. d->password->setEchoMode(QLineEdit::Password);
  202. d->password->setToolTip(tr("Password for authorization at proxy server"));
  203. QLabel *password = new QLabel(tr("P&assword:"), this);
  204. password->setBuddy(d->password);
  205. QGridLayout *proxyLay = new QGridLayout(d->proxyGroup);
  206. proxyLay->addWidget(type, 0, 0);
  207. proxyLay->addWidget(d->type, 0, 1);
  208. proxyLay->addWidget(host, 1, 0);
  209. proxyLay->addWidget(d->host, 1, 1, 1, 3);
  210. proxyLay->addWidget(port, 1, 4);
  211. proxyLay->addWidget(d->port, 1, 5);
  212. proxyLay->addWidget(userName, 2, 0);
  213. proxyLay->addWidget(d->userName, 2, 1);
  214. proxyLay->addWidget(password, 2, 2);
  215. proxyLay->addWidget(d->password, 2, 3, 1, 3);
  216. QLabel *url = new QLabel(QString("<a style='text-decoration:none; color:#1a4d82;' href='#'>%1</a>").arg(tr("Network files")), this);
  217. url->setToolTip(tr("Open folder with network files"));
  218. url->setAlignment(Qt::AlignRight);
  219. connect(url, SIGNAL(linkActivated(const QString &)), SLOT(openFolder()));
  220. QVBoxLayout *mainLay = new QVBoxLayout(this);
  221. mainLay->addWidget(serverGroup);
  222. mainLay->addSpacing(12);
  223. mainLay->addWidget(d->proxyGroup);
  224. mainLay->addStretch();
  225. mainLay->addWidget(url);
  226. mainLay->setContentsMargins(3, 3, 3, 0);
  227. }
  228. NetworkSettings::~NetworkSettings() { delete d; }
  229. void NetworkSettings::reset(int page)
  230. {
  231. if (page == m_id) {
  232. d->network->reset();
  233. d->welcome->setChecked(true);
  234. d->proxyGroup->setChecked(false);
  235. d->host->clear();
  236. d->port->setValue(3128);
  237. d->userName->clear();
  238. d->password->clear();
  239. }
  240. }
  241. void NetworkSettings::save()
  242. {
  243. int modified = d->network->save(false);
  244. if (SimpleSettings->getBool("HideWelcome") != d->welcome->isChecked()) {
  245. SimpleSettings->setBool("HideWelcome", d->welcome->isChecked());
  246. SimpleSettings->notify(Settings::HideWelcomeChanged);
  247. }
  248. modified += SimpleSettings->save("Proxy/Enable", d->proxyGroup->isChecked());
  249. int proxyPref = 0;
  250. proxyPref += SimpleSettings->save("Proxy/Type", d->type->currentIndex());
  251. proxyPref += SimpleSettings->save("Proxy/Port", d->port->value());
  252. proxyPref += SimpleSettings->save("Proxy/Host", d->host->text());
  253. proxyPref += SimpleSettings->save("Proxy/UserName", d->userName->text());
  254. proxyPref += SimpleSettings->save("Proxy/Password", d->password->text());
  255. if (d->proxyGroup->isChecked())
  256. modified += proxyPref;
  257. if (modified) {
  258. SimpleSettings->setApplicationProxy();
  259. SimpleSettings->notify(Settings::NetworkSettingsChanged);
  260. }
  261. }
  262. void NetworkSettings::openFolder()
  263. {
  264. SettingsDialog::openFolder(Settings::NetworksPath);
  265. }
  266. class InterfaceSettings::Private
  267. {
  268. public:
  269. Private() {}
  270. LanguageBox *language;
  271. #if !defined(SCHAT_NO_STYLE)
  272. QComboBox *mainStyle;
  273. #endif
  274. #ifndef SCHAT_NO_WEBKIT
  275. void createStylesList();
  276. void reloadVariants(int index);
  277. void setStyle();
  278. QCheckBox *grouping;
  279. QComboBox *chatStyle;
  280. QComboBox *chatStyleVariant;
  281. #endif
  282. };
  283. #ifndef SCHAT_NO_WEBKIT
  284. void InterfaceSettings::Private::createStylesList()
  285. {
  286. QStringList stylesDirs = SimpleSettings->path(Settings::StylesPath);
  287. int index = 0;
  288. for (int i = 0; i < stylesDirs.count(); ++i) {
  289. QString dir = stylesDirs.at(i) + '/';
  290. QDir qdir(dir);
  291. qdir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
  292. qdir.setSorting(QDir::Name);
  293. QStringList entryList = qdir.entryList();
  294. if (entryList.contains("Default"))
  295. entryList.removeAll("Default");
  296. foreach (QString style, entryList) {
  297. QString styleDirPath = dir + style;
  298. if (ChatWindowStyle::isValid(styleDirPath)) {
  299. index++;
  300. chatStyle->addItem(style);
  301. chatStyle->setItemData(index, QStringList(ChatWindowStyle::variants(styleDirPath + "/Contents/Resources/Variants/").keys()), Qt::UserRole + 1);
  302. }
  303. }
  304. }
  305. }
  306. void InterfaceSettings::Private::reloadVariants(int index)
  307. {
  308. chatStyleVariant->clear();
  309. chatStyleVariant->addItem(tr("(without variants)"));
  310. if (index > 0) {
  311. chatStyleVariant->addItems(chatStyle->itemData(index, Qt::UserRole + 1).toStringList());
  312. }
  313. else if (index == 0)
  314. chatStyleVariant->addItem("Monospace");
  315. }
  316. void InterfaceSettings::Private::setStyle()
  317. {
  318. QString style = SimpleSettings->getString("ChatStyle");
  319. int index = chatStyle->findText(style);
  320. if (index != -1) {
  321. chatStyle->setCurrentIndex(index);
  322. reloadVariants(index);
  323. QString styleVariant = SimpleSettings->getString("ChatStyleVariant");
  324. int variant = chatStyleVariant->findText(styleVariant);
  325. if (variant != -1)
  326. chatStyleVariant->setCurrentIndex(variant);
  327. }
  328. else
  329. reloadVariants(0);
  330. }
  331. #endif
  332. /*!
  333. * \brief ??????????? ?????? InterfaceSettings.
  334. */
  335. InterfaceSettings::InterfaceSettings(QWidget *parent)
  336. : AbstractSettingsPage(SettingsDialog::InterfacePage, parent), d(new Private)
  337. {
  338. #if !defined(SCHAT_NO_STYLE)
  339. d->mainStyle = new QComboBox(this);
  340. d->mainStyle->addItems(QStyleFactory::keys());
  341. d->mainStyle->setCurrentIndex(d->mainStyle->findText(SimpleSettings->getString("Style")));
  342. QGroupBox *mainStyleGroup = new QGroupBox(tr("&Global style"), this);
  343. QHBoxLayout *mainStyleLay = new QHBoxLayout(mainStyleGroup);
  344. mainStyleLay->addWidget(d->mainStyle);
  345. mainStyleLay->addStretch();
  346. mainStyleLay->setMargin(6);
  347. mainStyleLay->setSpacing(4);
  348. #endif
  349. QGroupBox *language = new QGroupBox(tr("Language"), this);
  350. d->language = new LanguageBox(SimpleChatApp::instance()->translation(), this);
  351. QHBoxLayout *languageLay = new QHBoxLayout(language);
  352. languageLay->addWidget(d->language);
  353. languageLay->addStretch();
  354. languageLay->setMargin(6);
  355. languageLay->setSpacing(4);
  356. #if !defined(SCHAT_NO_STYLE)
  357. QHBoxLayout *topLay = new QHBoxLayout;
  358. topLay->addWidget(mainStyleGroup, 0);
  359. topLay->addWidget(language, 1);
  360. #endif
  361. #ifndef SCHAT_NO_WEBKIT
  362. d->chatStyle = new QComboBox(this);
  363. d->chatStyle->addItem("Default");
  364. QLabel *name = new QLabel(tr("&Style name:"), this);
  365. name->setBuddy(d->chatStyle);
  366. d->chatStyleVariant = new QComboBox(this);
  367. QLabel *variant = new QLabel(tr("&Variant:"), this);
  368. variant->setBuddy(d->chatStyleVariant);
  369. d->grouping = new QCheckBox(tr("Group &consecutive messages"), this);
  370. d->grouping->setToolTip(tr("Group consecutive messages from one user, if the chosen style supports this option"));
  371. d->grouping->setChecked(SimpleSettings->getBool("MessageGrouping"));
  372. QGroupBox *chatStyleGroup = new QGroupBox(tr("&Text style"), this);
  373. QGridLayout *chatStyleLay = new QGridLayout(chatStyleGroup);
  374. chatStyleLay->addWidget(name, 0, 0);
  375. chatStyleLay->addWidget(d->chatStyle, 0, 1);
  376. chatStyleLay->addWidget(variant, 1, 0);
  377. chatStyleLay->addWidget(d->chatStyleVariant, 1, 1);
  378. chatStyleLay->addWidget(d->grouping, 2, 0, 1, 2);
  379. chatStyleLay->setColumnStretch(1, 1);
  380. chatStyleLay->setMargin(6);
  381. chatStyleLay->setSpacing(4);
  382. #endif
  383. QVBoxLayout *mainLay = new QVBoxLayout(this);
  384. #if !defined(SCHAT_NO_STYLE)
  385. mainLay->addLayout(topLay);
  386. #else
  387. mainLay->addWidget(language);
  388. #endif
  389. #ifndef SCHAT_NO_WEBKIT
  390. mainLay->addSpacing(12);
  391. mainLay->addWidget(chatStyleGroup);
  392. #endif
  393. mainLay->addStretch();
  394. mainLay->setContentsMargins(3, 3, 3, 0);
  395. #ifndef SCHAT_NO_WEBKIT
  396. connect(d->chatStyle, SIGNAL(currentIndexChanged(int)), SLOT(reloadVariants(int)));
  397. d->createStylesList();
  398. d->setStyle();
  399. #endif
  400. }
  401. InterfaceSettings::~InterfaceSettings() { delete d; }
  402. void InterfaceSettings::reset(int page)
  403. {
  404. if (page == m_id) {
  405. #if !defined(SCHAT_NO_STYLE)
  406. d->mainStyle->setCurrentIndex(d->mainStyle->findText(SimpleChatApp::defaultStyle()));
  407. #endif
  408. #ifndef SCHAT_NO_WEBKIT
  409. d->chatStyle->setCurrentIndex(0);
  410. d->chatStyleVariant->setCurrentIndex(0);
  411. d->grouping->setChecked(false);
  412. #endif
  413. }
  414. }
  415. void InterfaceSettings::save()
  416. {
  417. #if !defined(SCHAT_NO_STYLE)
  418. if (d->mainStyle->currentIndex() != -1) {
  419. SimpleSettings->setString("Style", d->mainStyle->currentText()) ;
  420. QApplication::setStyle(d->mainStyle->currentText());
  421. }
  422. #endif
  423. #ifndef SCHAT_NO_WEBKIT
  424. if (d->chatStyle->currentIndex() != -1)
  425. SimpleSettings->setString("ChatStyle", d->chatStyle->currentText());
  426. if (d->chatStyleVariant->currentIndex() == 0)
  427. SimpleSettings->setString("ChatStyleVariant", "");
  428. else if (d->chatStyleVariant->currentIndex() > 0)
  429. SimpleSettings->setString("ChatStyleVariant", d->chatStyleVariant->currentText());
  430. SimpleSettings->setBool("MessageGrouping", d->grouping->isChecked());
  431. SimpleSettings->notify(Settings::InterfaceSettingsChanged);
  432. #endif
  433. if (d->language->save()) {
  434. SimpleSettings->setString("Translation", SimpleChatApp::instance()->translation()->name());
  435. }
  436. }
  437. #ifndef SCHAT_NO_WEBKIT
  438. void InterfaceSettings::reloadVariants(int index)
  439. {
  440. d->reloadVariants(index);
  441. }
  442. #endif
  443. class EmoticonsSettings::Private
  444. {
  445. public:
  446. Private() {}
  447. bool createThemeList();
  448. QCheckBox *requireSpaces;
  449. QComboBox *combo;
  450. QGroupBox *group;
  451. };
  452. bool EmoticonsSettings::Private::createThemeList()
  453. {
  454. combo->addItems(Emoticons::themeList());
  455. if (combo->count() == 0)
  456. return false;
  457. combo->setCurrentIndex(combo->findText(SimpleSettings->getString("EmoticonTheme")));
  458. if (combo->currentIndex() == -1) {
  459. combo->setCurrentIndex(combo->findText("Kolobok"));
  460. if (combo->currentIndex() == -1) {
  461. combo->setCurrentIndex(0);
  462. }
  463. }
  464. return true;
  465. }
  466. /*!
  467. * \brief ??????????? ?????? EmoticonsSettings.
  468. */
  469. EmoticonsSettings::EmoticonsSettings(QWidget *parent)
  470. : AbstractSettingsPage(SettingsDialog::EmoticonsPage, parent), d(new Private)
  471. {
  472. d->combo = new QComboBox(this);
  473. d->group = new QGroupBox(tr("&Emoticons"), this);
  474. d->group->setCheckable(true);
  475. d->group->setChecked(SimpleSettings->getBool("UseEmoticons"));
  476. connect(d->group, SIGNAL(clicked(bool)), SLOT(enable(bool)));
  477. QHBoxLayout *themeLay = new QHBoxLayout(d->group);
  478. themeLay->addWidget(new QLabel(tr("Theme:"), this));
  479. themeLay->addWidget(d->combo);
  480. themeLay->addStretch();
  481. themeLay->setMargin(6);
  482. themeLay->setSpacing(4);
  483. QVBoxLayout *mainLay = new QVBoxLayout(this);
  484. mainLay->addWidget(d->group);
  485. d->requireSpaces = new QCheckBox(tr("Emoticons are &separated by spaces"), this);
  486. d->requireSpaces->setToolTip(tr("Show emoticons only if they are separated by spaces from the rest of the message"));
  487. d->requireSpaces->setChecked(Emoticons::strictParse());
  488. QLabel *url = new QLabel(QString("<a style='text-decoration:none; color:#1a4d82;' href='#'>%1</a>").arg(tr("Emoticons themes")), this);
  489. url->setToolTip(tr("Open folder with emoticons themes"));
  490. url->setAlignment(Qt::AlignRight);
  491. connect(url, SIGNAL(linkActivated(const QString &)), SLOT(openFolder()));
  492. mainLay->addWidget(d->requireSpaces);
  493. mainLay->addStretch();
  494. mainLay->addWidget(url);
  495. mainLay->setSpacing(4);
  496. mainLay->setContentsMargins(3, 3, 3, 0);
  497. if (!d->createThemeList()) {
  498. d->group->setEnabled(false);
  499. d->group->setChecked(false);
  500. SimpleSettings->setBool("UseEmoticons", false);
  501. }
  502. enable(d->group->isChecked());
  503. }
  504. EmoticonsSettings::~EmoticonsSettings() { delete d; }
  505. void EmoticonsSettings::reset(int page)
  506. {
  507. if (page == m_id) {
  508. d->group->setChecked(true);
  509. d->requireSpaces->setChecked(true);
  510. d->combo->setCurrentIndex(d->combo->findText("Kolobok"));
  511. enable(true);
  512. }
  513. }
  514. void EmoticonsSettings::save()
  515. {
  516. SimpleSettings->setBool("UseEmoticons", d->group->isChecked());
  517. Emoticons::setStrictParse(d->requireSpaces->isChecked());
  518. SimpleSettings->setString("EmoticonTheme", d->combo->currentText());
  519. SimpleSettings->notify(Settings::EmoticonsChanged);
  520. }
  521. void EmoticonsSettings::enable(bool checked)
  522. {
  523. d->requireSpaces->setEnabled(checked);
  524. }
  525. void EmoticonsSettings::openFolder()
  526. {
  527. SettingsDialog::openFolder(Settings::EmoticonsPath);
  528. }
  529. class SoundSettings::Private
  530. {
  531. public:
  532. Private() {}
  533. QGroupBox *enable;
  534. SoundWidget *msg;
  535. SoundWidget *privateMsg;
  536. #ifdef Q_WS_X11
  537. QGroupBox *useCmd;
  538. QLineEdit *cmd;
  539. #endif
  540. };
  541. /*!
  542. * \brief ??????????? ?????? SoundSettings.
  543. */
  544. SoundSettings::SoundSettings(QWidget *parent)
  545. : AbstractSettingsPage(SettingsDialog::SoundPage, parent), d(new Private)
  546. {
  547. d->enable = new QGroupBox(tr("Sound notifications"), this);
  548. d->enable->setCheckable(true);
  549. d->enable->setChecked(SimpleSettings->getBool("Sound"));
  550. QStringList sounds = SimpleSettings->path(Settings::SoundsPath);
  551. QStringList nameFilter = SimpleSettings->getList("Sound/NameFilter");
  552. QStringList list;
  553. foreach (QString path, sounds) {
  554. QDir dir(path);
  555. foreach (QString file, dir.entryList(nameFilter, QDir::Files)) {
  556. if (!list.contains(file))
  557. list << file;
  558. }
  559. }
  560. d->msg = new SoundWidget("Message", tr("Message"), tr("Message to main channel"), list, this);
  561. connect(d->msg, SIGNAL(play(const QString &)), SLOT(play(const QString &)));
  562. d->privateMsg = new SoundWidget("PrivateMessage", tr("Private message"), tr("Private message from another user"), list, this);
  563. connect(d->privateMsg, SIGNAL(play(const QString &)), SLOT(play(const QString &)));
  564. QVBoxLayout *soundLay = new QVBoxLayout(d->enable);
  565. soundLay->addWidget(d->msg);
  566. soundLay->addWidget(d->privateMsg);
  567. soundLay->setMargin(6);
  568. soundLay->setSpacing(0);
  569. #ifdef Q_WS_X11
  570. d->useCmd = new QGroupBox(tr("External command for sound play"), this);
  571. d->useCmd->setCheckable(true);
  572. d->useCmd->setChecked(SimpleSettings->getBool("Sound/UseExternalCmd"));
  573. d->cmd = new QLineEdit(SimpleSettings->getString("Sound/ExternalCmd"), this);
  574. d->cmd->setToolTip(tr("External command, instead of %1 sound file name is inserted"));
  575. QVBoxLayout *cmdLay = new QVBoxLayout(d->useCmd);
  576. cmdLay->addWidget(d->cmd);
  577. #endif
  578. QLabel *url = new QLabel(QString("<a style='text-decoration:none; color:#1a4d82;' href='#'>%1</a>").arg(tr("Sounds")), this);
  579. url->setToolTip(tr("Open folder with sounds"));
  580. url->setAlignment(Qt::AlignRight);
  581. connect(url, SIGNAL(linkActivated(const QString &)), SLOT(openFolder()));
  582. QVBoxLayout *mainLay = new QVBoxLayout(this);
  583. mainLay->addWidget(d->enable);
  584. #ifdef Q_WS_X11
  585. mainLay->addWidget(d->useCmd);
  586. #endif
  587. mainLay->addStretch();
  588. mainLay->addWidget(url);
  589. mainLay->setContentsMargins(3, 3, 3, 0);
  590. }
  591. SoundSettings::~SoundSettings() { delete d; }
  592. void SoundSettings::reset(int page)
  593. {
  594. if (page == m_id) {
  595. d->enable->setChecked(true);
  596. d->msg->reset(true, "Received.wav");
  597. d->privateMsg->reset(true, "Received.wav");
  598. #ifdef Q_WS_X11
  599. d->useCmd->setChecked(true);
  600. d->cmd->setText("aplay -q -N %1");
  601. #endif
  602. }
  603. }
  604. void SoundSettings::save()
  605. {
  606. int modified = 0;
  607. modified += SimpleSettings->save("Sound", d->enable->isChecked());
  608. modified += d->msg->save();
  609. modified += d->privateMsg->save();
  610. #ifdef Q_WS_X11
  611. modified += SimpleSettings->save("Sound/UseExternalCmd", d->useCmd->isChecked());
  612. modified += SimpleSettings->save("Sound/ExternalCmd", d->cmd->text());
  613. #endif
  614. if (modified)
  615. SimpleSettings->notify(Settings::SoundChanged);
  616. }
  617. void SoundSettings::openFolder()
  618. {
  619. SettingsDialog::openFolder(Settings::SoundsPath);
  620. }
  621. void SoundSettings::play(const QString &file)
  622. {
  623. #ifdef Q_WS_X11
  624. if (d->useCmd->isChecked() && !d->cmd->text().isEmpty())
  625. QProcess::startDetached(d->cmd->text().arg(file));
  626. else
  627. #endif
  628. QSound::play(file);
  629. }
  630. class NotificationSettings::Private
  631. {
  632. public:
  633. Private() {}
  634. QCheckBox *autoAway;
  635. QCheckBox *privateMsg;
  636. QCheckBox *publicMsg;
  637. QCheckBox *timeOut;
  638. QGroupBox *popupGroup;
  639. QSpinBox *timeOutSpin;
  640. };
  641. /*!
  642. * \brief ??????????? ?????? NotificationSettings.
  643. */
  644. NotificationSettings::NotificationSettings(QWidget *parent)
  645. : AbstractSettingsPage(SettingsDialog::NotificationPage, parent), d(new Private)
  646. {
  647. d->privateMsg = new QCheckBox(tr("Private message"), this);
  648. d->privateMsg->setToolTip(tr("Notification of private messages"));
  649. d->privateMsg->setChecked(SimpleSettings->getBool("Notification"));
  650. d->publicMsg = new QCheckBox(tr("Personal message in main channel"), this);
  651. d->publicMsg->setToolTip(tr("Notification of personal messages by nick in the main channel"));
  652. d->publicMsg->setChecked(SimpleSettings->getBool("NotificationPublic"));
  653. QGroupBox *eventGroup = new QGroupBox(tr("Notification of events"), this);
  654. QVBoxLayout *eventLay = new QVBoxLayout(eventGroup);
  655. eventLay->addWidget(d->privateMsg);
  656. eventLay->addWidget(d->publicMsg);
  657. eventLay->setMargin(6);
  658. eventLay->setSpacing(0);
  659. d->timeOut = new QCheckBox(tr("Automatically close after:"), this);
  660. d->timeOut->setToolTip(tr("Automatically close notification windows after a set number of seconds"));
  661. d->timeOut->setChecked(SimpleSettings->getBool("PopupAutoClose"));
  662. d->timeOutSpin = new QSpinBox(this);
  663. d->timeOutSpin->setRange(1, 1440);
  664. d->timeOutSpin->setSuffix(tr(" sec"));
  665. d->timeOutSpin->setValue(SimpleSettings->getInt("PopupAutoCloseTime"));
  666. d->autoAway = new QCheckBox(tr("But not with automatic \"Away\" status"), this);
  667. d->autoAway->setToolTip(tr("Do not close automatic pop-up windows at automatic \"Away\" status"));
  668. d->autoAway->setChecked(SimpleSettings->getBool("NoPopupAutoCloseInAway"));
  669. d->popupGroup = new QGroupBox(tr("Notification window settings"), this);
  670. QGridLayout *popupLay = new QGridLayout(d->popupGroup);
  671. popupLay->addWidget(d->timeOut, 0, 0, 1, 2);
  672. popupLay->addWidget(d->timeOutSpin, 0, 2);
  673. popupLay->addItem(new QSpacerItem(20, 0), 1, 0);
  674. popupLay->addWidget(d->autoAway, 1, 1, 1, 2);
  675. popupLay->setColumnStretch(1, 1);
  676. popupLay->setMargin(6);
  677. popupLay->setSpacing(0);
  678. QVBoxLayout *mainLay = new QVBoxLayout(this);
  679. mainLay->addWidget(eventGroup);
  680. mainLay->addSpacing(12);
  681. mainLay->addWidget(d->popupGroup);
  682. mainLay->addStretch();
  683. mainLay->setContentsMargins(3, 3, 3, 0);
  684. d->autoAway->setEnabled(d->timeOut->isChecked());
  685. d->timeOutSpin->setEnabled(d->timeOut->isChecked());
  686. popupGroupState();
  687. connect(d->timeOut, SIGNAL(clicked(bool)), d->autoAway, SLOT(setEnabled(bool)));
  688. connect(d->timeOut, SIGNAL(clicked(bool)), d->timeOutSpin, SLOT(setEnabled(bool)));
  689. connect(d->privateMsg, SIGNAL(clicked(bool)), SLOT(popupGroupState()));
  690. connect(d->publicMsg, SIGNAL(clicked(bool)), SLOT(popupGroupState()));
  691. }
  692. NotificationSettings::~NotificationSettings() { delete d; }
  693. void NotificationSettings::reset(int page)
  694. {
  695. if (page == m_id) {
  696. d->privateMsg->setChecked(true);
  697. d->publicMsg->setChecked(true);
  698. d->timeOut->setChecked(true);
  699. d->autoAway->setChecked(true);
  700. d->autoAway->setEnabled(true);
  701. d->timeOutSpin->setValue(10);
  702. d->timeOutSpin->setEnabled(true);
  703. d->popupGroup->setEnabled(true);
  704. }
  705. }
  706. void NotificationSettings::save()
  707. {
  708. int modified = 0;
  709. modified += SimpleSettings->save("Notification", d->privateMsg->isChecked());
  710. modified += SimpleSettings->save("NotificationPublic", d->publicMsg->isChecked());
  711. modified += SimpleSettings->save("PopupAutoClose", d->timeOut->isChecked());
  712. modified += SimpleSettings->save("PopupAutoCloseTime", d->timeOutSpin->value());
  713. modified += SimpleSettings->save("NoPopupAutoCloseInAway", d->autoAway->isChecked());
  714. if (modified)
  715. SimpleSettings->notify(Settings::NotificationChanged);
  716. }
  717. void NotificationSettings::popupGroupState()
  718. {
  719. d->popupGroup->setEnabled(d->privateMsg->isChecked() || d->publicMsg->isChecked());
  720. }
  721. class StatusesSettings::Private
  722. {
  723. public:
  724. Private() {}
  725. QCheckBox *autoAway;
  726. QCheckBox *dnd;
  727. QCheckBox *exitAwayOnSend;
  728. QCheckBox *muteInDnD;
  729. QComboBox *statuses;
  730. QSpinBox *autoAwayTime;
  731. };
  732. /*!
  733. * \brief ??????????? ?????? StatusesSettings.
  734. */
  735. StatusesSettings::StatusesSettings(QWidget *parent)
  736. : AbstractSettingsPage(SettingsDialog::StatusesPage, parent), d(new Private)
  737. {
  738. d->exitAwayOnSend = new QCheckBox(tr("Reset the status after sending the message"), this);
  739. d->exitAwayOnSend->setChecked(SimpleSettings->getBool("ExitAwayOnSend"));
  740. QLabel *statusLabel = new QLabel(tr("&Status:"), this);
  741. d->statuses = new QComboBox(this);
  742. d->statuses->addItem(tr("Away"));
  743. d->statuses->addItem(tr("Do Not Disturb"));
  744. connect(d->statuses, SIGNAL(currentIndexChanged(int)), this, SLOT(showOptions(int)));
  745. statusLabel->setBuddy(d->statuses);
  746. QGroupBox *group = new QGroupBox(tr("Status options"), this);
  747. d->autoAway = new QCheckBox(tr("Switch on the status after idle time:"), this);
  748. d->autoAway->setToolTip(tr("Turn automatically status Away after idle time and return to the standard mode if the activity occurred"));
  749. d->autoAway->setChecked(SimpleSettings->getBool("AutoAway"));
  750. d->autoAwayTime = new QSpinBox(this);
  751. d->autoAwayTime->setRange(1, 1440);
  752. d->autoAwayTime->setSuffix(tr(" min"));
  753. d->autoAwayTime->setValue(SimpleSettings->getInt("AutoAwayTime"));
  754. d->muteInDnD = new QCheckBox(tr("The status switches off the sound"), this);
  755. d->muteInDnD->setToolTip(tr("Use of “Do Not Disturb” status switches off the sound"));
  756. d->muteInDnD->setChecked(SimpleSettings->getBool("Sound/MuteInDnD"));
  757. d->dnd = new QCheckBox(tr("The status switches off the notification windows"), this);
  758. d->dnd->setToolTip(tr("Use of “Do Not Disturb” status switches off the notification windows"));
  759. d->dnd->setChecked(SimpleSettings->getBool("NoNotificationInDnD"));
  760. connect(d->autoAway, SIGNAL(clicked(bool)), d->autoAwayTime, SLOT(setEnabled(bool)));
  761. d->autoAwayTime->setEnabled(d->autoAway->isChecked());
  762. QGridLayout *groupLay = new QGridLayout(group);
  763. groupLay->addWidget(d->autoAway, 0, 0);
  764. groupLay->addWidget(d->autoAwayTime, 0, 1);
  765. groupLay->addWidget(d->muteInDnD, 1, 0, 1, 2);
  766. groupLay->addWidget(d->dnd, 2, 0, 1, 2);
  767. groupLay->setColumnStretch(0, 1);
  768. groupLay->setMargin(6);
  769. groupLay->setSpacing(4);
  770. QHBoxLayout *statusesLay = new QHBoxLayout;
  771. statusesLay->addWidget(statusLabel);
  772. statusesLay->addWidget(d->statuses);
  773. statusesLay->addStretch();
  774. statusesLay->setMargin(6);
  775. statusesLay->setSpacing(4);
  776. QVBoxLayout *mainLay = new QVBoxLayout(this);
  777. mainLay->addWidget(d->exitAwayOnSend);
  778. mainLay->addSpacing(12);
  779. mainLay->addLayout(statusesLay);
  780. mainLay->addWidget(group);
  781. mainLay->addStretch();
  782. mainLay->setContentsMargins(3, 3, 3, 0);
  783. showOptions(0);
  784. }
  785. StatusesSettings::~StatusesSettings() { delete d; }
  786. void StatusesSettings::reset(int page)
  787. {
  788. if (page == m_id) {
  789. d->autoAway->setChecked(true);
  790. d->autoAwayTime->setValue(10);
  791. d->autoAwayTime->setEnabled(true);
  792. d->exitAwayOnSend->setChecked(true);
  793. d->muteInDnD->setChecked(true);
  794. d->dnd->setChecked(true);
  795. }
  796. }
  797. void StatusesSettings::save()
  798. {
  799. int modified = 0;
  800. modified += SimpleSettings->save("AutoAway", d->autoAway->isChecked());
  801. modified += SimpleSettings->save("AutoAwayTime", d->autoAwayTime->value());
  802. modified += SimpleSettings->save("ExitAwayOnSend", d->exitAwayOnSend->isChecked());
  803. if (modified)
  804. SimpleSettings->notify(Settings::AwaySettingsChanged);
  805. if (SimpleSettings->save("Sound/MuteInDnD", d->muteInDnD->isChecked()))
  806. SimpleSettings->notify(Settings::SoundChanged);
  807. if (SimpleSettings->save("NoNotificationInDnD", d->dnd->isChecked()))
  808. SimpleSettings->notify(Settings::NotificationChanged);
  809. }
  810. void StatusesSettings::showOptions(int index)
  811. {
  812. if (index == 0) {
  813. d->autoAway->setVisible(true);
  814. d->autoAwayTime->setVisible(true);
  815. d->muteInDnD->setVisible(false);
  816. d->dnd->setVisible(false);
  817. }
  818. else {
  819. d->autoAway->setVisible(false);
  820. d->autoAwayTime->setVisible(false);
  821. d->muteInDnD->setVisible(true);
  822. d->dnd->setVisible(true);
  823. }
  824. }
  825. class MiscSettings::Private
  826. {
  827. public:
  828. Private() {}
  829. void readAutostart();
  830. void writeAutostart();
  831. QCheckBox *autostart;
  832. QCheckBox *log;
  833. QCheckBox *logPrivate;
  834. #if defined(SCHAT_NO_UPDATE)
  835. QCheckBox *updateGroup;
  836. #else
  837. QGroupBox *updateGroup;
  838. QCheckBox *autoDownload;
  839. #endif
  840. #if defined(Q_WS_WIN)
  841. QCheckBox *autostartDaemon;
  842. #endif
  843. };
  844. /*!
  845. * ????????????? ????????? ??????? ?????????? ? ????????????.
  846. * ???? ???? ????????? ?????????? ???????? ?? ??????, ?? ???????? ?????? ???????.
  847. * ???? ????? ? ??????? ?? ???????, ??????? ??????.
  848. */
  849. void MiscSettings::Private::readAutostart()
  850. {
  851. #if defined(Q_WS_WIN)
  852. QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
  853. if (QFile::exists(QApplication::applicationDirPath() + "/schatd-ui.exe")) {
  854. QString value = reg.value(QApplication::applicationName() + " Daemon", "").toString();
  855. if (value.isEmpty())
  856. autostartDaemon->setChecked(false);
  857. }
  858. else
  859. autostartDaemon->setVisible(false);
  860. QString value = reg.value(QApplication::applicationName(), "").toString();
  861. if (value.isEmpty())
  862. autostart->setChecked(false);
  863. #elif defined(Q_WS_X11)
  864. QString desktopFile = QDir::homePath() + "/.config/autostart/schat.desktop";
  865. if (!QFile::exists(desktopFile) || QSettings(desktopFile, QSettings::IniFormat).value("Desktop Entry/X-GNOME-Autostart-enabled").toBool() == false) {
  866. autostart->setChecked(false);
  867. return;
  868. }
  869. #endif
  870. }
  871. /*!
  872. * ?????????/??????? ??? ? ??? ????????????? ?????? ?? ????????????.
  873. */
  874. void MiscSettings::Private::writeAutostart()
  875. {
  876. #if defined(Q_WS_WIN)
  877. QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
  878. if (autostart->checkState() == Qt::Checked)
  879. reg.setValue(QApplication::applicationName(), QDir::toNativeSeparators(QApplication::applicationFilePath()) + " -hide");
  880. else if (autostart->checkState() == Qt::Unchecked)
  881. reg.remove(QApplication::applicationName());
  882. if (autostartDaemon->isVisible()) {
  883. if (autostart->checkState() == Qt::Checked)
  884. reg.setValue(QApplication::applicationName() + " Daemon", QDir::toNativeSeparators(QApplication::applicationDirPath() + "/schatd-ui.exe") + " -start");
  885. else if (autostart->checkState() == Qt::Unchecked)
  886. reg.remove(QApplication::applicationName() + " Daemon");
  887. }
  888. #elif defined(Q_WS_X11)
  889. QString path = QDir::homePath() + "/.config/autostart/";
  890. if (autostart->checkState() == Qt::Checked) {
  891. if (!QDir().exists(path))
  892. QDir().mkpath(path);
  893. QFile file(path + "schat.desktop");
  894. if (file.open(QFile::WriteOnly | QFile::Truncate)) {
  895. QTextStream out(&file);
  896. out << "[Desktop Entry]" << endl;
  897. out << "Version=1.0" << endl;
  898. out << "Type=Application" << endl;
  899. out << "Name=IMPOMEZIA Simple Chat" << endl;
  900. out << "Comment=" << endl;
  901. out << "Icon=schat" << endl;
  902. out << "Exec=schat -hide" << endl;
  903. out << "Hidden=false" << endl;
  904. out << "NoDisplay=false" << endl;
  905. out << "X-GNOME-Autostart-enabled=true" << endl;
  906. file.close();
  907. }
  908. }
  909. else if (autostart->checkState() == Qt::Unchecked) {
  910. QFile::remove(path + "schat.desktop");
  911. }
  912. #endif
  913. }
  914. /*!
  915. * \brief ??????????? ?????? MiscSettings.
  916. */
  917. MiscSettings::MiscSettings(QWidget *parent)
  918. : AbstractSettingsPage(SettingsDialog::MiscPage, parent), d(new Private)
  919. {
  920. QGroupBox *integration = new QGroupBox(tr("Integration"), this);
  921. #if defined(Q_OS_MAC)
  922. integration->setVisible(false);
  923. #endif
  924. d->autostart = new QCheckBox(tr("&Autorun"), this);
  925. d->autostart->setToolTip(tr("Autorun at system startup"));
  926. d->autostart->setTristate();
  927. d->autostart->setCheckState(Qt::PartiallyChecked);
  928. #ifdef Q_WS_WIN
  929. d->autostartDaemon = new QCheckBox(tr("&Server autorun"), this);
  930. d->autostartDaemon->setToolTip(tr("Server autorun at system startup"));
  931. d->autostartDaemon->setTristate();
  932. d->autostartDaemon->setCheckState(Qt::PartiallyChecked);
  933. #endif
  934. QVBoxLayout *integrationLay = new QVBoxLayout(integration);
  935. integrationLay->addWidget(d->autostart);
  936. #ifdef Q_WS_WIN
  937. integrationLay->addWidget(d->autostartDaemon);
  938. #endif
  939. integrationLay->setMargin(6);
  940. integrationLay->setSpacing(4);
  941. QGroupBox *logGroup = new QGroupBox(tr("&Logging"), this);
  942. d->log = new QCheckBox(tr("&Main channel log"), this);
  943. d->log->setToolTip(tr("Keep a log of main channel"));
  944. d->log->setChecked(SimpleSettings->getBool("Log"));
  945. d->logPrivate = new QCheckBox(tr("&Private logs"), this);
  946. d->logPrivate->setToolTip(tr("Keep logs of private messages"));
  947. d->logPrivate->setChecked(SimpleSettings->getBool("LogPrivate"));
  948. QVBoxLayout *logLay = new QVBoxLayout(logGroup);
  949. logLay->addWidget(d->log);
  950. logLay->addWidget(d->logPrivate);
  951. logLay->setMargin(6);
  952. logLay->setSpacing(4);
  953. #if defined(SCHAT_NO_UPDATE)
  954. d->updateGroup = new QCheckBox(tr("Checks for updates"), this);
  955. #else
  956. d->updateGroup = new QGroupBox(tr("Checks for updates"), this);
  957. #endif
  958. d->updateGroup->setCheckable(true);
  959. d->updateGroup->setChecked(SimpleSettings->getBool("Updates/Enable"));
  960. #if !defined(SCHAT_NO_UPDATE)
  961. d->autoDownload = new QCheckBox(tr("Automatically download updates"), this);
  962. d->autoDownload->setChecked(SimpleSettings->getBool("Updates/AutoDownload"));
  963. QVBoxLayout *updateLay = new QVBoxLayout(d->updateGroup);
  964. updateLay->addWidget(d->autoDownload);
  965. updateLay->setContentsMargins(16, 6, 6, 6);
  966. updateLay->setSpacing(0);
  967. #endif
  968. QVBoxLayout *mainLay = new QVBoxLayout(this);
  969. mainLay->addWidget(integration);
  970. #if !defined(Q_OS_MAC)
  971. mainLay->addSpacing(12);
  972. #endif
  973. mainLay->addWidget(logGroup);
  974. mainLay->addSpacing(12);
  975. mainLay->addWidget(d->updateGroup);
  976. mainLay->addStretch();
  977. mainLay->setContentsMargins(3, 3, 3, 0);
  978. d->readAutostart();
  979. }
  980. MiscSettings::~MiscSettings() { delete d; }
  981. void MiscSettings::reset(int page)
  982. {
  983. if (page == m_id) {
  984. d->log->setChecked(true);
  985. d->logPrivate->setChecked(true);
  986. d->updateGroup->setChecked(true);
  987. #if !defined(SCHAT_NO_UPDATE)
  988. d->autoDownload->setChecked(false);
  989. #endif
  990. }
  991. }
  992. void MiscSettings::save()
  993. {
  994. d->writeAutostart();
  995. SimpleSettings->setBool("Log", d->log->isChecked());
  996. SimpleSettings->setBool("LogPrivate", d->logPrivate->isChecked());
  997. SimpleSettings->setBool("Updates/Enable", d->updateGroup->isChecked());
  998. #if !defined(SCHAT_NO_UPDATE)
  999. SimpleSettings->setBool("Updates/AutoDownload", d->autoDownload->isChecked());
  1000. #endif
  1001. SimpleSettings->notify(Settings::MiscSettingsChanged);
  1002. }