Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
031acae3
Commit
031acae3
authored
Nov 30, 2009
by
ck
Browse files
Maemo: Complete options page.
parent
28e3ba5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.cpp
View file @
031acae3
...
...
@@ -54,7 +54,7 @@ namespace {
};
MaemoDeviceConfigurations
::
DeviceConfig
::
DeviceConfig
(
const
QString
&
name
)
:
name
(
name
),
type
(
Physical
)
:
name
(
name
),
type
(
Physical
)
,
port
(
22
),
timeout
(
30
)
{
}
...
...
@@ -97,8 +97,10 @@ void MaemoDeviceConfigurations::save()
QSettings
*
settings
=
Core
::
ICore
::
instance
()
->
settings
();
settings
->
beginGroup
(
SettingsGroup
);
settings
->
beginWriteArray
(
ConfigListKey
,
m_devConfigs
.
count
());
foreach
(
const
DeviceConfig
&
devConfig
,
m_devConfigs
)
devConfig
.
save
(
*
settings
);
for
(
int
i
=
0
;
i
<
m_devConfigs
.
count
();
++
i
)
{
settings
->
setArrayIndex
(
i
);
m_devConfigs
.
at
(
i
).
save
(
*
settings
);
}
settings
->
endArray
();
settings
->
endGroup
();
}
...
...
@@ -114,8 +116,10 @@ void MaemoDeviceConfigurations::load()
QSettings
*
settings
=
Core
::
ICore
::
instance
()
->
settings
();
settings
->
beginGroup
(
SettingsGroup
);
int
count
=
settings
->
beginReadArray
(
ConfigListKey
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
settings
->
setArrayIndex
(
i
);
m_devConfigs
.
append
(
DeviceConfig
(
*
settings
));
}
settings
->
endArray
();
settings
->
endGroup
();
}
...
...
src/plugins/qt4projectmanager/qt-maemo/maemodeviceconfigurations.h
View file @
031acae3
...
...
@@ -65,6 +65,18 @@ public:
int
timeout
;
};
class
DevConfMatcher
{
public:
DevConfMatcher
(
const
QString
&
name
)
:
m_name
(
name
)
{}
bool
operator
()(
const
MaemoDeviceConfigurations
::
DeviceConfig
&
devConfig
)
{
return
devConfig
.
name
==
m_name
;
}
private:
const
QString
m_name
;
};
static
MaemoDeviceConfigurations
&
instance
();
QList
<
DeviceConfig
>
devConfigs
()
const
{
return
m_devConfigs
;
}
void
setDevConfigs
(
const
QList
<
DeviceConfig
>
&
devConfigs
);
...
...
src/plugins/qt4projectmanager/qt-maemo/maemosettingspage.cpp
View file @
031acae3
...
...
@@ -46,6 +46,8 @@
#include "ui_maemosettingswidget.h"
#include "maemosettingspage.h"
#include <QtGui/QIntValidator>
#include <algorithm>
namespace
Qt4ProjectManager
{
...
...
@@ -54,16 +56,61 @@ namespace Internal {
#define PAGE_ID "ZZ.Maemo Device Configurations"
#define PAGE_ID_TR "Maemo Device Configurations"
class
DevConfMatcher
bool
configNameExists
(
const
QList
<
MaemoDeviceConfigurations
::
DeviceConfig
>
&
devConfs
,
const
QString
&
name
)
{
return
std
::
find_if
(
devConfs
.
constBegin
(),
devConfs
.
constEnd
(),
MaemoDeviceConfigurations
::
DevConfMatcher
(
name
))
!=
devConfs
.
constEnd
();
}
class
PortAndTimeoutValidator
:
public
QIntValidator
{
public:
DevConfMatcher
(
const
QString
&
name
)
:
m_name
(
name
)
{}
bool
operator
()(
const
MaemoDeviceConfigurations
::
DeviceConfig
&
devConfig
)
PortAndTimeoutValidator
()
:
QIntValidator
(
0
,
SHRT_MAX
,
0
)
{
return
devConfig
.
name
==
m_name
;
}
void
setValue
(
int
oldValue
)
{
m_oldValue
=
oldValue
;
}
virtual
void
fixup
(
QString
&
input
)
const
{
int
dummy
=
0
;
if
(
validate
(
input
,
dummy
)
!=
Acceptable
)
input
=
QString
::
number
(
m_oldValue
);
}
private:
const
QString
m_name
;
int
m_oldValue
;
};
class
NameValidator
:
public
QValidator
{
public:
NameValidator
(
const
QList
<
MaemoDeviceConfigurations
::
DeviceConfig
>
&
devConfs
)
:
m_devConfs
(
devConfs
)
{
}
void
setName
(
const
QString
&
name
)
{
m_oldName
=
name
;
}
virtual
State
validate
(
QString
&
input
,
int
&
/* pos */
)
const
{
if
(
input
.
trimmed
().
isEmpty
()
||
(
input
!=
m_oldName
&&
configNameExists
(
m_devConfs
,
input
)))
return
Intermediate
;
return
Acceptable
;
}
virtual
void
fixup
(
QString
&
input
)
const
{
int
dummy
=
0
;
if
(
validate
(
input
,
dummy
)
!=
Acceptable
)
input
=
m_oldName
;
}
private:
QString
m_oldName
;
const
QList
<
MaemoDeviceConfigurations
::
DeviceConfig
>
&
m_devConfs
;
};
...
...
@@ -72,24 +119,44 @@ class MaemoSettingsWidget : public QWidget
Q_OBJECT
public:
MaemoSettingsWidget
(
QWidget
*
parent
);
~
MaemoSettingsWidget
();
void
saveSettings
();
private
slots
:
void
selectionChanged
();
void
addConfig
();
void
deleteConfig
();
void
configNameEditingFinished
();
void
deviceTypeChanged
();
void
hostNameEditingFinished
();
void
portEditingFinished
();
void
timeoutEditingFinished
();
void
userNameEditingFinished
();
void
passwordEditingFinished
();
private:
void
initGui
();
void
addConfig
();
void
display
(
const
MaemoDeviceConfigurations
::
DeviceConfig
&
devConfig
);
MaemoDeviceConfigurations
::
DeviceConfig
&
currentConfig
();
void
setPortOrTimeout
(
const
QLineEdit
*
lineEdit
,
int
&
confVal
,
PortAndTimeoutValidator
&
validator
);
void
clearDetails
();
Ui_maemoSettingsWidget
*
m_ui
;
QList
<
MaemoDeviceConfigurations
::
DeviceConfig
>
m_devConfs
;
PortAndTimeoutValidator
m_portValidator
;
PortAndTimeoutValidator
m_timeoutValidator
;
NameValidator
m_nameValidator
;
};
MaemoSettingsPage
::
MaemoSettingsPage
(
QObject
*
parent
)
:
Core
::
IOptionsPage
(
parent
)
,
m_widget
(
0
)
:
Core
::
IOptionsPage
(
parent
)
{
qDebug
(
"Creating maemo settings page"
);
}
MaemoSettingsPage
::~
MaemoSettingsPage
()
{
qDebug
(
"deleting maemo settings page"
);
}
QString
MaemoSettingsPage
::
id
()
const
...
...
@@ -115,8 +182,6 @@ QString MaemoSettingsPage::trCategory() const
QWidget
*
MaemoSettingsPage
::
createPage
(
QWidget
*
parent
)
{
if
(
m_widget
!=
0
)
delete
m_widget
;
m_widget
=
new
MaemoSettingsWidget
(
parent
);
return
m_widget
;
}
...
...
@@ -134,15 +199,25 @@ void MaemoSettingsPage::finish()
MaemoSettingsWidget
::
MaemoSettingsWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
),
m_ui
(
new
Ui_maemoSettingsWidget
),
m_devConfs
(
MaemoDeviceConfigurations
::
instance
().
devConfigs
())
m_devConfs
(
MaemoDeviceConfigurations
::
instance
().
devConfigs
()),
m_nameValidator
(
m_devConfs
)
{
qDebug
(
"creating maemo settings widget"
);
initGui
();
}
MaemoSettingsWidget
::~
MaemoSettingsWidget
()
{
qDebug
(
"Deleting maemo settings widget"
);
}
void
MaemoSettingsWidget
::
initGui
()
{
m_ui
->
setupUi
(
this
);
m_ui
->
nameLineEdit
->
setValidator
(
&
m_nameValidator
);
m_ui
->
portLineEdit
->
setValidator
(
&
m_portValidator
);
m_ui
->
timeoutLineEdit
->
setValidator
(
&
m_timeoutValidator
);
foreach
(
const
MaemoDeviceConfigurations
::
DeviceConfig
&
devConf
,
m_devConfs
)
m_ui
->
configListWidget
->
addItem
(
devConf
.
name
);
}
...
...
@@ -155,14 +230,32 @@ void MaemoSettingsWidget::addConfig()
bool
isUnique
=
false
;
do
{
newName
=
prefix
+
QString
::
number
(
suffix
++
);
isUnique
=
std
::
find_if
(
m_devConfs
.
constBegin
(),
m_devConfs
.
constEnd
(),
DevConfMatcher
(
newName
))
==
m_devConfs
.
constEnd
();
isUnique
=
!
configNameExists
(
m_devConfs
,
newName
);
}
while
(
!
isUnique
);
m_devConfs
.
append
(
MaemoDeviceConfigurations
::
DeviceConfig
(
newName
));
m_ui
->
configListWidget
->
addItem
(
newName
);
// TODO: select and display new item (selection should automatically lead to display)
// also mark configuration name to suggest overwriting
m_ui
->
configListWidget
->
setCurrentRow
(
m_ui
->
configListWidget
->
count
()
-
1
);
m_ui
->
nameLineEdit
->
selectAll
();
m_ui
->
removeConfigButton
->
setEnabled
(
true
);
m_ui
->
nameLineEdit
->
setFocus
();
}
void
MaemoSettingsWidget
::
deleteConfig
()
{
const
QList
<
QListWidgetItem
*>
&
selectedItems
=
m_ui
->
configListWidget
->
selectedItems
();
if
(
selectedItems
.
isEmpty
())
return
;
QListWidgetItem
*
item
=
selectedItems
.
first
();
const
int
selectedRow
=
m_ui
->
configListWidget
->
row
(
item
);
m_devConfs
.
removeAt
(
selectedRow
);
disconnect
(
m_ui
->
configListWidget
,
SIGNAL
(
itemSelectionChanged
()),
0
,
0
);
delete
m_ui
->
configListWidget
->
takeItem
(
selectedRow
);
connect
(
m_ui
->
configListWidget
,
SIGNAL
(
itemSelectionChanged
()),
this
,
SLOT
(
selectionChanged
()));
Q_ASSERT
(
m_ui
->
configListWidget
->
count
()
==
m_devConfs
.
count
());
selectionChanged
();
}
void
MaemoSettingsWidget
::
display
(
const
MaemoDeviceConfigurations
::
DeviceConfig
&
devConfig
)
...
...
@@ -178,6 +271,10 @@ void MaemoSettingsWidget::display(const MaemoDeviceConfigurations::DeviceConfig
m_ui
->
userLineEdit
->
setText
(
devConfig
.
uname
);
m_ui
->
pwdLineEdit
->
setText
(
devConfig
.
pwd
);
m_ui
->
detailsWidget
->
setEnabled
(
true
);
m_nameValidator
.
setName
(
devConfig
.
name
);
m_portValidator
.
setValue
(
devConfig
.
port
);
m_timeoutValidator
.
setValue
(
devConfig
.
timeout
);
m_ui
->
detailsWidget
->
setEnabled
(
true
);
}
void
MaemoSettingsWidget
::
saveSettings
()
...
...
@@ -185,6 +282,95 @@ void MaemoSettingsWidget::saveSettings()
MaemoDeviceConfigurations
::
instance
().
setDevConfigs
(
m_devConfs
);
}
MaemoDeviceConfigurations
::
DeviceConfig
&
MaemoSettingsWidget
::
currentConfig
()
{
qDebug
(
"%d/%d"
,
m_ui
->
configListWidget
->
count
(),
m_devConfs
.
count
());
Q_ASSERT
(
m_ui
->
configListWidget
->
count
()
==
m_devConfs
.
count
());
const
QList
<
QListWidgetItem
*>
&
selectedItems
=
m_ui
->
configListWidget
->
selectedItems
();
Q_ASSERT
(
selectedItems
.
count
()
==
1
);
const
int
selectedRow
=
m_ui
->
configListWidget
->
row
(
selectedItems
.
first
());
qDebug
(
"selected row = %d"
,
selectedRow
);
Q_ASSERT
(
selectedRow
<
m_devConfs
.
count
());
return
m_devConfs
[
selectedRow
];
}
void
MaemoSettingsWidget
::
configNameEditingFinished
()
{
const
QString
&
newName
=
m_ui
->
nameLineEdit
->
text
();
currentConfig
().
name
=
newName
;
m_nameValidator
.
setName
(
newName
);
m_ui
->
configListWidget
->
currentItem
()
->
setText
(
newName
);
}
void
MaemoSettingsWidget
::
deviceTypeChanged
()
{
currentConfig
().
type
=
m_ui
->
deviceButton
->
isChecked
()
?
MaemoDeviceConfigurations
::
DeviceConfig
::
Physical
:
MaemoDeviceConfigurations
::
DeviceConfig
::
Simulator
;
}
void
MaemoSettingsWidget
::
hostNameEditingFinished
()
{
currentConfig
().
host
=
m_ui
->
hostLineEdit
->
text
();
}
void
MaemoSettingsWidget
::
portEditingFinished
()
{
setPortOrTimeout
(
m_ui
->
portLineEdit
,
currentConfig
().
port
,
m_portValidator
);
}
void
MaemoSettingsWidget
::
timeoutEditingFinished
()
{
setPortOrTimeout
(
m_ui
->
timeoutLineEdit
,
currentConfig
().
timeout
,
m_timeoutValidator
);
}
void
MaemoSettingsWidget
::
setPortOrTimeout
(
const
QLineEdit
*
lineEdit
,
int
&
confVal
,
PortAndTimeoutValidator
&
validator
)
{
bool
ok
;
confVal
=
lineEdit
->
text
().
toInt
(
&
ok
);
Q_ASSERT
(
ok
);
validator
.
setValue
(
confVal
);
}
void
MaemoSettingsWidget
::
userNameEditingFinished
()
{
currentConfig
().
uname
=
m_ui
->
userLineEdit
->
text
();
}
void
MaemoSettingsWidget
::
passwordEditingFinished
()
{
currentConfig
().
pwd
=
m_ui
->
pwdLineEdit
->
text
();
}
void
MaemoSettingsWidget
::
selectionChanged
()
{
const
QList
<
QListWidgetItem
*>
&
selectedItems
=
m_ui
->
configListWidget
->
selectedItems
();
Q_ASSERT
(
selectedItems
.
count
()
<=
1
);
if
(
selectedItems
.
isEmpty
())
{
m_ui
->
removeConfigButton
->
setEnabled
(
false
);
clearDetails
();
m_ui
->
detailsWidget
->
setEnabled
(
false
);
}
else
{
m_ui
->
removeConfigButton
->
setEnabled
(
true
);
display
(
currentConfig
());
}
}
void
MaemoSettingsWidget
::
clearDetails
()
{
m_ui
->
nameLineEdit
->
clear
();
m_ui
->
hostLineEdit
->
clear
();
m_ui
->
portLineEdit
->
clear
();
m_ui
->
timeoutLineEdit
->
clear
();
m_ui
->
userLineEdit
->
clear
();
m_ui
->
pwdLineEdit
->
clear
();
}
}
// namespace Internal
}
// namespace Qt4ProjectManager
...
...
src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui
View file @
031acae3
...
...
@@ -146,6 +146,9 @@
</item>
<item>
<widget
class=
"QPushButton"
name=
"removeConfigButton"
>
<property
name=
"enabled"
>
<bool>
false
</bool>
</property>
<property
name=
"text"
>
<string>
Remove
</string>
</property>
...
...
@@ -169,5 +172,194 @@
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>
nameLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
configNameEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
221
</x>
<y>
166
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
514
</x>
<y>
321
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
deviceButton
</sender>
<signal>
toggled(bool)
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
deviceTypeChanged()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
164
</x>
<y>
197
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
511
</x>
<y>
279
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
hostLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
hostNameEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
289
</x>
<y>
222
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
424
</x>
<y>
231
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
portLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
portEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
320
</x>
<y>
248
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
514
</x>
<y>
352
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
timeoutLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
timeoutEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
371
</x>
<y>
276
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
425
</x>
<y>
187
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
userLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
userNameEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
340
</x>
<y>
302
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
422
</x>
<y>
301
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
pwdLineEdit
</sender>
<signal>
editingFinished()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
passwordEditingFinished()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
243
</x>
<y>
333
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
423
</x>
<y>
336
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
simulatorButton
</sender>
<signal>
toggled(bool)
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
deviceTypeChanged()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
291
</x>
<y>
198
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
426
</x>
<y>
87
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
addConfigButton
</sender>
<signal>
clicked()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
addConfig()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
465
</x>
<y>
27
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
516
</x>
<y>
118
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
configListWidget
</sender>
<signal>
itemSelectionChanged()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
selectionChanged()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
365
</x>
<y>
56
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
420
</x>
<y>
151
</y>
</hint>
</hints>
</connection>
<connection>
<sender>
removeConfigButton
</sender>
<signal>
clicked()
</signal>
<receiver>
maemoSettingsWidget
</receiver>
<slot>
deleteConfig()
</slot>
<hints>
<hint
type=
"sourcelabel"
>
<x>
454
</x>
<y>
56
</y>
</hint>
<hint
type=
"destinationlabel"
>
<x>
513
</x>
<y>
101
</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>
configNameEditingFinished()
</slot>
<slot>
deviceTypeChanged()
</slot>
<slot>
hostNameEditingFinished()
</slot>
<slot>
portEditingFinished()
</slot>
<slot>
timeoutEditingFinished()
</slot>
<slot>
userNameEditingFinished()
</slot>
<slot>
passwordEditingFinished()
</slot>
<slot>
addConfig()
</slot>
<slot>
selectionChanged()
</slot>
<slot>
deleteConfig()
</slot>
</slots>
</ui>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment