PageRenderTime 36ms CodeModel.GetById 20ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/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
22#include <QMessageBox>
23
24settings_dialog::settings_dialog() : QDialog()
25{
26	setupUi( this );
27	
28	settings = new QSettings( "EWItool", "EWItool" );
29	libraryLocation_lineEdit->setText( settings->value( "library/location" ).toString() );
30	if (settings->contains( "PatchExchange/UserID" ))
31		pxUserID_lineEdit->setText( settings->value( "PatchExchange/UserID" ).toString() );
32	if (settings->contains( "PatchExchange/Password" ))
33		pxPasswrd_lineEdit->setText( settings->value( "PatchExchange/Password" ).toString() );
34	if (settings->contains( "PatchExchange/Server" ))
35		pxServer_lineEdit->setText( settings->value( "PatchExchange/Server" ).toString() );
36	
37	px = new patchExchange( this );	// the 'this' is critical...
38	
39	connect( clear_pushButton, SIGNAL(clicked()), this, SLOT( clearSettings() ) );
40	connect( test_pushButton, SIGNAL(clicked()), this, SLOT( testEPX() ) );
41	connect( px, SIGNAL(connectionState(QString)), this, SLOT( updateConnectionState( QString ) ) );
42	connect( px, SIGNAL(loginState(QString)), this, SLOT( updateConnectionState( QString ) ) );
43}
44
45
46settings_dialog::~settings_dialog()
47{
48	delete px;
49}
50
51void settings_dialog::clearSettings() {
52	
53	if (QMessageBox::question( this, "EWItool - Settings",
54		tr( "This will remove all settings for EWItool, including the MIDI port settings.\n\n"
55			"Do you really want to do this?" ),
56		QMessageBox::No | QMessageBox::Yes) == QMessageBox::No) return;
57	
58	settings->clear();
59	QDialog::done( true );
60}
61
62void settings_dialog::accept() {
63	
64	bool changes = false;
65	
66	if (settings->value( "library/location" ).toString() != libraryLocation_lineEdit->text() ) {
67		changes = true;
68		settings->setValue( "library/location", libraryLocation_lineEdit->text() );
69	}
70	if (settings->value( "PatchExchange/UserID" ).toString() != pxUserID_lineEdit->text() ) {
71		changes = true;
72		settings->setValue( "PatchExchange/UserID", pxUserID_lineEdit->text() );
73	}
74	if (settings->value( "PatchExchange/Password" ).toString() != pxPasswrd_lineEdit->text() ) {
75		changes = true;
76		settings->setValue( "PatchExchange/Password", pxPasswrd_lineEdit->text() );
77	}
78	if (settings->value( "PatchExchange/Server" ).toString() != pxServer_lineEdit->text() ) {
79		changes = true;
80		settings->setValue( "PatchExchange/Server", pxServer_lineEdit->text() );
81	}
82	
83	QDialog::done( changes == true );
84}
85
86void settings_dialog::testEPX() {
87	px->testConnection( pxServer_lineEdit->text() );
88	px->testUser( pxServer_lineEdit->text(),  pxUserID_lineEdit->text(), pxPasswrd_lineEdit->text() );
89}
90
91void settings_dialog::updateConnectionState( QString state ){
92	pxTest_label->setText( state );
93}
94