PageRenderTime 30ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mmapper-2.1.0-source/src/preferences/groupmanagerpage.cpp

#
C++ | 128 lines | 86 code | 15 blank | 27 comment | 24 complexity | 9633bfc185cd5d995d922f007e1757fa MD5 | raw file
Possible License(s): GPL-2.0
  1. /************************************************************************
  2. **
  3. ** Authors: Nils Schimmelmann <nschimme@gmail.com> (Jahara)
  4. **
  5. ** This file is part of the MMapper project.
  6. ** Maintained by Nils Schimmelmann <nschimme@gmail.com>
  7. **
  8. ** This program is free software; you can redistribute it and/or
  9. ** modify it under the terms of the GNU General Public License
  10. ** as published by the Free Software Foundation; either version 2
  11. ** of the License, or (at your option) any later version.
  12. **
  13. ** This program is distributed in the hope that it will be useful,
  14. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ** GNU General Public License for more details.
  17. **
  18. ** You should have received a copy of the GNU General Public License
  19. ** along with this program; if not, write to the:
  20. ** Free Software Foundation, Inc.
  21. ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. **
  23. ************************************************************************/
  24. #include <QtGui>
  25. #include "groupmanagerpage.h"
  26. #include "configuration.h"
  27. GroupManagerPage::GroupManagerPage(CGroup* gm, QWidget *parent)
  28. : QWidget(parent)
  29. {
  30. setupUi(this);
  31. m_groupManager = gm;
  32. // Character Section
  33. connect( charName, SIGNAL( editingFinished() ), SLOT( charNameTextChanged() ) );
  34. connect( changeColor, SIGNAL(clicked()),SLOT(changeColorClicked()));
  35. connect( colorName, SIGNAL( editingFinished() ), SLOT( colorNameTextChanged() ) );
  36. // Host Section
  37. connect( localHost, SIGNAL( linkActivated (const QString&) ),
  38. SLOT( localHostLinkActivated(const QString&) ));
  39. connect( localPort, SIGNAL( valueChanged(int) ), SLOT( localPortValueChanged(int) ) );
  40. // Client Section
  41. connect( remoteHost, SIGNAL( editingFinished() ), SLOT( remoteHostTextChanged() ) );
  42. connect( remotePort, SIGNAL( valueChanged(int) ), SLOT( remotePortValueChanged(int) ) );
  43. // Checkbox Section
  44. connect( rulesWarning, SIGNAL(stateChanged(int)), SLOT(rulesWarningChanged(int)));
  45. charName->setText( Config().m_groupManagerCharName );
  46. colorName->setText( Config().m_groupManagerColor.name() );
  47. colorLabel->setPalette(QPalette(Config().m_groupManagerColor));
  48. colorLabel->setAutoFillBackground(true);
  49. localPort->setValue( Config().m_groupManagerLocalPort );
  50. remoteHost->setText( Config().m_groupManagerHost );
  51. remotePort->setValue( Config().m_groupManagerRemotePort );
  52. rulesWarning->setChecked( Config().m_groupManagerRulesWarning );
  53. }
  54. void GroupManagerPage::charNameTextChanged()
  55. {
  56. const QString newName = charName->text();
  57. if (!m_groupManager->isNamePresent(newName.toAscii()) &&
  58. Config().m_groupManagerCharName != newName) {
  59. Config().m_groupManagerCharName = newName.toAscii();
  60. m_groupManager->resetName();
  61. }
  62. }
  63. void GroupManagerPage::colorNameTextChanged()
  64. {
  65. const QColor newColor = QColor(colorName->text());
  66. if (newColor.isValid() && newColor != Config().m_groupManagerColor) {
  67. colorLabel->setPalette(QPalette(newColor));
  68. colorLabel->setAutoFillBackground(true);
  69. Config().m_groupManagerColor = newColor;
  70. m_groupManager->resetColor();
  71. }
  72. }
  73. void GroupManagerPage::changeColorClicked()
  74. {
  75. const QColor newColor = QColorDialog::getColor(Config().m_groupManagerColor, this);
  76. if (newColor.isValid() && newColor != Config().m_groupManagerColor) {
  77. colorName->setText(newColor.name());
  78. colorLabel->setPalette(QPalette(newColor));
  79. colorLabel->setAutoFillBackground(true);
  80. Config().m_groupManagerColor = newColor;
  81. m_groupManager->resetColor();
  82. }
  83. }
  84. void GroupManagerPage::remoteHostTextChanged()
  85. {
  86. if (QString(remoteHost->text()).toAscii() != Config().m_groupManagerHost) {
  87. Config().m_groupManagerHost = QString(remoteHost->text()).toAscii();
  88. }
  89. if (m_groupManager->isConnected() && m_groupManager->getType() == CGroupCommunicator::Client)
  90. m_groupManager->reconnect();
  91. }
  92. void GroupManagerPage::remotePortValueChanged(int)
  93. {
  94. if (remotePort->value() != Config().m_groupManagerRemotePort) {
  95. Config().m_groupManagerRemotePort = remotePort->value();
  96. }
  97. if (m_groupManager->isConnected() && m_groupManager->getType() == CGroupCommunicator::Client)
  98. m_groupManager->reconnect();
  99. }
  100. void GroupManagerPage::localHostLinkActivated(const QString &link) {
  101. QDesktopServices::openUrl(QUrl::fromEncoded(link.toAscii()));
  102. }
  103. void GroupManagerPage::localPortValueChanged(int)
  104. {
  105. if (localPort->value() != Config().m_groupManagerLocalPort && localPort->value() != int(Config().m_localPort))
  106. Config().m_groupManagerLocalPort = localPort->value();
  107. if (m_groupManager->getType() == CGroupCommunicator::Server)
  108. m_groupManager->reconnect();
  109. }
  110. void GroupManagerPage::rulesWarningChanged(int)
  111. {
  112. Config().m_groupManagerRulesWarning = rulesWarning->isChecked();
  113. }