/settings_dialog.cpp

http://ewitool.googlecode.com/ · C++ · 94 lines · 58 code · 17 blank · 19 comment · 14 complexity · 592dda4c6fd78ef93261bd1bad80c36a MD5 · raw file

  1. /***************************************************************************
  2. * Copyright (C) 2008 by Steve Merrony *
  3. * steve@brahma *
  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, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "settings_dialog.h"
  21. #include <QMessageBox>
  22. settings_dialog::settings_dialog() : QDialog()
  23. {
  24. setupUi( this );
  25. settings = new QSettings( "EWItool", "EWItool" );
  26. libraryLocation_lineEdit->setText( settings->value( "library/location" ).toString() );
  27. if (settings->contains( "PatchExchange/UserID" ))
  28. pxUserID_lineEdit->setText( settings->value( "PatchExchange/UserID" ).toString() );
  29. if (settings->contains( "PatchExchange/Password" ))
  30. pxPasswrd_lineEdit->setText( settings->value( "PatchExchange/Password" ).toString() );
  31. if (settings->contains( "PatchExchange/Server" ))
  32. pxServer_lineEdit->setText( settings->value( "PatchExchange/Server" ).toString() );
  33. px = new patchExchange( this ); // the 'this' is critical...
  34. connect( clear_pushButton, SIGNAL(clicked()), this, SLOT( clearSettings() ) );
  35. connect( test_pushButton, SIGNAL(clicked()), this, SLOT( testEPX() ) );
  36. connect( px, SIGNAL(connectionState(QString)), this, SLOT( updateConnectionState( QString ) ) );
  37. connect( px, SIGNAL(loginState(QString)), this, SLOT( updateConnectionState( QString ) ) );
  38. }
  39. settings_dialog::~settings_dialog()
  40. {
  41. delete px;
  42. }
  43. void settings_dialog::clearSettings() {
  44. if (QMessageBox::question( this, "EWItool - Settings",
  45. tr( "This will remove all settings for EWItool, including the MIDI port settings.\n\n"
  46. "Do you really want to do this?" ),
  47. QMessageBox::No | QMessageBox::Yes) == QMessageBox::No) return;
  48. settings->clear();
  49. QDialog::done( true );
  50. }
  51. void settings_dialog::accept() {
  52. bool changes = false;
  53. if (settings->value( "library/location" ).toString() != libraryLocation_lineEdit->text() ) {
  54. changes = true;
  55. settings->setValue( "library/location", libraryLocation_lineEdit->text() );
  56. }
  57. if (settings->value( "PatchExchange/UserID" ).toString() != pxUserID_lineEdit->text() ) {
  58. changes = true;
  59. settings->setValue( "PatchExchange/UserID", pxUserID_lineEdit->text() );
  60. }
  61. if (settings->value( "PatchExchange/Password" ).toString() != pxPasswrd_lineEdit->text() ) {
  62. changes = true;
  63. settings->setValue( "PatchExchange/Password", pxPasswrd_lineEdit->text() );
  64. }
  65. if (settings->value( "PatchExchange/Server" ).toString() != pxServer_lineEdit->text() ) {
  66. changes = true;
  67. settings->setValue( "PatchExchange/Server", pxServer_lineEdit->text() );
  68. }
  69. QDialog::done( changes == true );
  70. }
  71. void settings_dialog::testEPX() {
  72. px->testConnection( pxServer_lineEdit->text() );
  73. px->testUser( pxServer_lineEdit->text(), pxUserID_lineEdit->text(), pxPasswrd_lineEdit->text() );
  74. }
  75. void settings_dialog::updateConnectionState( QString state ){
  76. pxTest_label->setText( state );
  77. }