Commit 698fd3c2b47f876b5ef053d0028d594ca8e34df9

  • avatar
  • Seb Ruiz <ruiz @k…e.org>
  • Sun Aug 30 02:44:52 CEST 2009
MySQL database configuration support. Thanks to John Atkinson for the patch!
CCMAIL: john@fauxnetic.co.uk
ChangeLog
(1 / 2)
  
6262 The video can be appended to the playlist, and rendered within the applet.
6363 * Photo applet to show images from Flickr, with customizable animations.
6464 * Customizable user interface using dock widgets.
65 * Support for external MySQL database. See
66 http://amarok.kde.org/wiki/MySQL_Server.
65 * Support for external MySQL database.
6766 * GHNS integration for downloading and installing Context applets.
6867 * Support for Context applets to be written in QtScript.
6968 * Custom Dynamic Playlists using Last.fm.
  
187187 configdialog/dialogs/OsdConfig.cpp
188188 configdialog/dialogs/PlaybackConfig.cpp
189189 configdialog/dialogs/ServiceConfig.cpp
190 configdialog/dialogs/DatabaseConfig.cpp
190191)
191192
192193kde4_add_ui_files(libconfigdialog_SRCS
195195 configdialog/dialogs/GeneralConfig.ui
196196 configdialog/dialogs/OsdConfig.ui
197197 configdialog/dialogs/PlaybackConfig.ui
198 configdialog/dialogs/DatabaseConfig.ui
198199)
199200
200201set(libbrowserframework_SRCS
  
2727#include "OsdConfig.h"
2828#include "PlaybackConfig.h"
2929#include "ServiceConfig.h"
30#include "DatabaseConfig.h"
3031
3132#include <KLocale>
3233
4848 ConfigDialogBase* services = new ServiceConfig( this );
4949 ConfigDialogBase* playback = new PlaybackConfig( this );
5050 ConfigDialogBase* osd = new OsdConfig( this );
51 ConfigDialogBase* database = new DatabaseConfig( this );
5152
5253 connect( general, SIGNAL( lockLayout( bool ) ), The::mainWindow(), SLOT ( setLayoutLocked( bool ) ) );
5354
5959 addPage( services, i18n( "Internet Services" ), "services-amarok", i18n( "Configure Services" ) );
6060 addPage( playback, i18n( "Playback" ), "preferences-media-playback-amarok", i18n( "Configure Playback" ) );
6161 addPage( osd, i18n( "On Screen Display" ), "preferences-indicator-amarok", i18n( "Configure On-Screen-Display" ) );
62 addPage( database, i18n( "Database" ), "preferences-database-amarok", i18n( "Configure Database" ) );
6263// addPage( mediadevice, i18n( "Media Devices" ), "preferences-multimedia-player-amarok", i18n( "Configure Portable Player Support" ) );
6364
6465 setButtons( Help | Ok | Apply | Cancel );
  
1/****************************************************************************************
2 * Copyright (c) 2009 John Atkinson <john@fauxnetic.co.uk> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Pulic License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17#include "DatabaseConfig.h"
18
19#include "Amarok.h"
20#include "Debug.h"
21
22#include <KCMultiDialog>
23
24
25DatabaseConfig::DatabaseConfig( QWidget* parent )
26 : ConfigDialogBase( parent )
27{
28 setupUi( this );
29 readConfiguration();
30
31 connect( kcfg_UseInternalDB, SIGNAL( stateChanged(int) ), SLOT( toggleExternalConfigAvailable(int) ) );
32
33 connect( kcfg_DBName, SIGNAL( editingFinished() ), SLOT( updateSQLQuery() ) );
34 connect( kcfg_Username, SIGNAL( editingFinished() ), SLOT( updateSQLQuery() ) );
35 connect( kcfg_Server, SIGNAL( editingFinished() ), SLOT( updateSQLQuery() ) );
36
37}
38
39DatabaseConfig::~DatabaseConfig()
40{}
41
42
43///////////////////////////////////////////////////////////////
44// REIMPLEMENTED METHODS from ConfigDialogBase
45///////////////////////////////////////////////////////////////
46
47bool
48DatabaseConfig::hasChanged()
49{
50 return false;
51}
52
53bool
54DatabaseConfig::isDefault()
55{
56 return false;
57}
58
59void
60DatabaseConfig::updateSettings()
61{
62 writeConfiguration();
63}
64
65
66///////////////////////////////////////////////////////////////
67// PRIVATE METHODS
68///////////////////////////////////////////////////////////////
69
70void
71DatabaseConfig::readConfiguration()
72{
73 KConfigGroup config = Amarok::config( "MySQL" );
74
75 kcfg_UseInternalDB->setChecked( !config.readEntry( "UseServer", false ) );
76
77 kcfg_Server->setText( config.readEntry( "Host", "localhost" ).toUtf8() );
78 kcfg_Port->setValue( config.readEntry( "Port", "3306" ).toInt() );
79 kcfg_DBName->setText( config.readEntry( "Database", "amarokdb" ).toUtf8() );
80
81 kcfg_Username->setText( config.readEntry( "User", "amarokuser" ).toUtf8() );
82 kcfg_Password->setText( config.readEntry( "Password", "" ).toUtf8() );
83
84
85 toggleExternalConfigAvailable(kcfg_UseInternalDB->checkState());
86 updateSQLQuery();
87}
88
89void
90DatabaseConfig::writeConfiguration()
91{
92 KConfigGroup config = Amarok::config( "MySQL" );
93
94 bool useExternal = (kcfg_UseInternalDB->checkState() != Qt::Checked);
95
96 config.writeEntry( "UseServer", useExternal );
97
98 if(useExternal)
99 {
100 config.writeEntry( "Host", kcfg_Server->text() );
101 config.writeEntry( "Port", kcfg_Port->value() );
102 config.writeEntry( "Database", kcfg_DBName->text() );
103 config.writeEntry( "User", kcfg_Username->text() );
104 config.writeEntry( "Password", kcfg_Password->text() );
105 }
106}
107
108
109void
110DatabaseConfig::toggleExternalConfigAvailable( int checkBoxState ) //SLOT
111{
112 bool enableExternalConfig = (checkBoxState != Qt::Checked);
113
114 kcfg_DatabaseEngine->setEnabled( enableExternalConfig );
115 group_Connection->setVisible( enableExternalConfig );
116
117}
118
119void
120DatabaseConfig::updateSQLQuery() //SLOT
121{
122 if(isSQLInfoPresent())
123 {
124 // Query template:
125 // GRANT ALL ON amarokdb.* TO 'amarokuser'@'localhost' IDENTIFIED BY 'mypassword'; FLUSH PRIVILEGES;
126
127 // Don't print the actual password!
128 QString examplePassword = i18nc( "A default password for insertion into an example SQL command (so as not to print the real one). To be manually replaced by the user.",
129 "password" );
130
131 text_SQL->setPlainText( "GRANT ALL ON " + kcfg_DBName->text() + ".* " +
132 "TO '" + kcfg_Username->text() + "'@'" + kcfg_Server->text() + "' " +
133 "IDENTIFIED BY '" + examplePassword + "';\n" +
134 "FLUSH PRIVILEGES;"
135 );
136 }
137 else
138 {
139 text_SQL->setPlainText("");
140 }
141
142}
143
144
145bool
146DatabaseConfig::isSQLInfoPresent()
147{
148 if( kcfg_DBName->text().isEmpty() || kcfg_Username->text().isEmpty() || kcfg_Server->text().isEmpty() )
149 {
150 return false;
151 }
152
153 return true;
154}
155
156
157#include "DatabaseConfig.moc"
  
1/****************************************************************************************
2 * Copyright (c) 2009 John Atkinson <john@fauxnetic.co.uk> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Pulic License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17#ifndef DATABASECONFIG_H
18#define DATABASECONFIG_H
19
20#include "ui_DatabaseConfig.h"
21#include "ConfigDialogBase.h"
22
23
24class DatabaseConfig : public ConfigDialogBase, public Ui_DatabaseConfig
25{
26 Q_OBJECT
27
28 public:
29 DatabaseConfig( QWidget* parent );
30 virtual ~DatabaseConfig();
31
32 virtual bool hasChanged();
33 virtual bool isDefault();
34 virtual void updateSettings();
35
36 protected:
37 void readConfiguration();
38 void writeConfiguration();
39
40 private Q_SLOTS:
41 void toggleExternalConfigAvailable( int checkBoxState );
42 void updateSQLQuery();
43
44 private:
45 bool isSQLInfoPresent();
46};
47
48
49#endif
  
1<?xml version="1.0" encoding="UTF-8"?>
2<ui version="4.0">
3 <class>DatabaseConfig</class>
4 <widget class="QWidget" name="DatabaseConfig">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>440</width>
10 <height>426</height>
11 </rect>
12 </property>
13 <layout class="QVBoxLayout" name="verticalLayout_2">
14 <item>
15 <widget class="QCheckBox" name="kcfg_UseInternalDB">
16 <property name="text">
17 <string>Use &amp;internal database (default)</string>
18 </property>
19 </widget>
20 </item>
21 <item>
22 <layout class="QGridLayout" name="gridLayout_4">
23 <item row="0" column="1">
24 <widget class="QComboBox" name="kcfg_DatabaseEngine">
25 <property name="sizePolicy">
26 <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
27 <horstretch>0</horstretch>
28 <verstretch>0</verstretch>
29 </sizepolicy>
30 </property>
31 <item>
32 <property name="text">
33 <string>MySQL</string>
34 </property>
35 </item>
36 </widget>
37 </item>
38 <item row="0" column="0">
39 <widget class="QLabel" name="label_DatabaseEngine">
40 <property name="text">
41 <string>&amp;External database engine:</string>
42 </property>
43 <property name="buddy">
44 <cstring>kcfg_DatabaseEngine</cstring>
45 </property>
46 </widget>
47 </item>
48 </layout>
49 </item>
50 <item>
51 <widget class="QGroupBox" name="group_Connection">
52 <property name="title">
53 <string>Connection Settings</string>
54 </property>
55 <layout class="QVBoxLayout" name="verticalLayout_3">
56 <item>
57 <layout class="QGridLayout" name="gridLayout_3">
58 <item row="0" column="0">
59 <widget class="QLabel" name="label_Server">
60 <property name="text">
61 <string>&amp;Server:</string>
62 </property>
63 <property name="textFormat">
64 <enum>Qt::AutoText</enum>
65 </property>
66 <property name="alignment">
67 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
68 </property>
69 <property name="buddy">
70 <cstring>kcfg_Server</cstring>
71 </property>
72 </widget>
73 </item>
74 <item row="0" column="1" colspan="3">
75 <widget class="QLineEdit" name="kcfg_Server">
76 <property name="text">
77 <string notr="true"/>
78 </property>
79 </widget>
80 </item>
81 <item row="0" column="4">
82 <widget class="QLabel" name="label_Port">
83 <property name="text">
84 <string>P&amp;ort:</string>
85 </property>
86 <property name="textFormat">
87 <enum>Qt::AutoText</enum>
88 </property>
89 <property name="alignment">
90 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
91 </property>
92 <property name="buddy">
93 <cstring>kcfg_Port</cstring>
94 </property>
95 </widget>
96 </item>
97 <item row="0" column="5">
98 <widget class="QSpinBox" name="kcfg_Port">
99 <property name="maximum">
100 <number>65535</number>
101 </property>
102 </widget>
103 </item>
104 <item row="1" column="0">
105 <widget class="QLabel" name="label_Username">
106 <property name="text">
107 <string>&amp;Username:</string>
108 </property>
109 <property name="textFormat">
110 <enum>Qt::AutoText</enum>
111 </property>
112 <property name="alignment">
113 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
114 </property>
115 <property name="buddy">
116 <cstring>kcfg_Username</cstring>
117 </property>
118 </widget>
119 </item>
120 <item row="2" column="1" colspan="5">
121 <widget class="QLineEdit" name="kcfg_Password">
122 <property name="inputMask">
123 <string notr="true"/>
124 </property>
125 <property name="text">
126 <string notr="true"/>
127 </property>
128 <property name="echoMode">
129 <enum>QLineEdit::Password</enum>
130 </property>
131 </widget>
132 </item>
133 <item row="2" column="0">
134 <widget class="QLabel" name="label_Password">
135 <property name="text">
136 <string>&amp;Password:</string>
137 </property>
138 <property name="textFormat">
139 <enum>Qt::AutoText</enum>
140 </property>
141 <property name="alignment">
142 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
143 </property>
144 <property name="buddy">
145 <cstring>kcfg_Password</cstring>
146 </property>
147 </widget>
148 </item>
149 <item row="1" column="1" colspan="5">
150 <widget class="QLineEdit" name="kcfg_Username">
151 <property name="text">
152 <string notr="true"/>
153 </property>
154 </widget>
155 </item>
156 <item row="3" column="0">
157 <widget class="QLabel" name="label_DBName">
158 <property name="text">
159 <string>&amp;Database:</string>
160 </property>
161 <property name="textFormat">
162 <enum>Qt::AutoText</enum>
163 </property>
164 <property name="alignment">
165 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
166 </property>
167 <property name="buddy">
168 <cstring>kcfg_DBName</cstring>
169 </property>
170 </widget>
171 </item>
172 <item row="3" column="1" colspan="5">
173 <widget class="QLineEdit" name="kcfg_DBName">
174 <property name="text">
175 <string notr="true"/>
176 </property>
177 </widget>
178 </item>
179 </layout>
180 </item>
181 <item>
182 <widget class="QFrame" name="frame_info">
183 <property name="frameShape">
184 <enum>QFrame::StyledPanel</enum>
185 </property>
186 <property name="frameShadow">
187 <enum>QFrame::Raised</enum>
188 </property>
189 <layout class="QVBoxLayout" name="verticalLayout">
190 <item>
191 <widget class="QLabel" name="label_Info">
192 <property name="font">
193 <font>
194 <pointsize>8</pointsize>
195 </font>
196 </property>
197 <property name="text">
198 <string>Amarok expects the above database and user account to already exist. This user also requires full access to the database.</string>
199 </property>
200 <property name="alignment">
201 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
202 </property>
203 <property name="wordWrap">
204 <bool>true</bool>
205 </property>
206 </widget>
207 </item>
208 <item>
209 <widget class="QLabel" name="label_SQL">
210 <property name="font">
211 <font>
212 <pointsize>8</pointsize>
213 </font>
214 </property>
215 <property name="text">
216 <string>Access rights can be assigned with the following S&amp;QL commands (after replacing the password with the correct one):</string>
217 </property>
218 <property name="wordWrap">
219 <bool>true</bool>
220 </property>
221 <property name="buddy">
222 <cstring>text_SQL</cstring>
223 </property>
224 </widget>
225 </item>
226 <item>
227 <widget class="QPlainTextEdit" name="text_SQL">
228 <property name="sizePolicy">
229 <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
230 <horstretch>0</horstretch>
231 <verstretch>0</verstretch>
232 </sizepolicy>
233 </property>
234 <property name="maximumSize">
235 <size>
236 <width>16777215</width>
237 <height>50</height>
238 </size>
239 </property>
240 <property name="font">
241 <font>
242 <pointsize>6</pointsize>
243 </font>
244 </property>
245 <property name="cursor" stdset="0">
246 <cursorShape>IBeamCursor</cursorShape>
247 </property>
248 <property name="acceptDrops">
249 <bool>false</bool>
250 </property>
251 <property name="readOnly">
252 <bool>true</bool>
253 </property>
254 <property name="plainText">
255 <string notr="true"/>
256 </property>
257 </widget>
258 </item>
259 </layout>
260 </widget>
261 </item>
262 </layout>
263 </widget>
264 </item>
265 <item>
266 <spacer name="verticalSpacer">
267 <property name="orientation">
268 <enum>Qt::Vertical</enum>
269 </property>
270 <property name="sizeHint" stdset="0">
271 <size>
272 <width>20</width>
273 <height>40</height>
274 </size>
275 </property>
276 </spacer>
277 </item>
278 </layout>
279 </widget>
280 <resources/>
281 <connections/>
282</ui>