summaryrefslogtreecommitdiff
path: root/noncore/apps/odict/configdlg.cpp
blob: 3d98f639e4acbd4caa0a0c03ea8089febdc8a6f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
   application:             : ODict

   begin                    : December 2002
   copyright                : ( C ) 2002, 2003 by Carsten Niehaus
   email                    : cniehaus@handhelds.org
 **************************************************************************/

/***************************************************************************
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by    *
 * the Free Software Foundation; either version 2 of the License, or       *
 * ( at your option ) any later version.                                   *
 *                                                                         *
 **************************************************************************/
#include "configdlg.h"
#include "searchmethoddlg.h"

#include <qpe/qpeapplication.h>
#include <qpe/config.h>

#include <qlayout.h>
#include <qvbox.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qlineedit.h>

ConfigDlg::ConfigDlg(QWidget *parent, const char *name, bool modal) : QDialog(parent, name, modal)
{
	setCaption( tr( "Options" ) );
	QVBoxLayout *vbox_layout = new QVBoxLayout( this );
	search_tab = new QWidget( this , "search_tab" );
	QVBoxLayout *vbox_layout_searchtab = new QVBoxLayout( search_tab, 4 , 4 ,"blah" );

	QHBox *hbox = new QHBox( search_tab );
	list = new QListView( hbox );
	list->addColumn( tr( "Searchmethod" ) );
	loadSearchMethodNames();

	QVBox *vbox = new QVBox( hbox );
	new_button = new QPushButton( tr( "New" ) , vbox );
	change_button = new QPushButton( tr( "Change" ) , vbox );
	delete_button = new QPushButton( tr( "Delete" ) , vbox );
	connect( new_button, SIGNAL( clicked() ), this, SLOT( slotNewMethod() ) );
	connect( change_button, SIGNAL( clicked() ), this, SLOT( slotChangeMethod() ));
	connect( delete_button, SIGNAL( clicked() ), this, SLOT( slotDeleteMethod() ));

	vbox_layout_searchtab->addWidget( hbox );

	vbox_layout->addWidget( search_tab );

 	QPEApplication::showDialog( this );
}

void ConfigDlg::slotNewMethod()
{
	SearchMethodDlg dlg( this, "SearchMethodDlg", true );
	if ( dlg.exec() == QDialog::Accepted )
	{
		dlg.saveItem();
		QListViewItem *item = new QListViewItem( list );
		item->setText( 0 , dlg.nameLE->text() );
	}
}

void ConfigDlg::slotChangeMethod()
{
	if ( list->selectedItem() )
	{
		SearchMethodDlg dlg( this, "SearchMethodDlg", true, list->selectedItem()->text( 0 ) );
		if ( dlg.exec() == QDialog::Accepted )
		{
			dlg.saveItem();
			QListViewItem *item = list->selectedItem();
			item->setText( 0 , dlg.nameLE->text() );
		}
	}
}

void ConfigDlg::slotDeleteMethod()
{
	if ( list->selectedItem() )
	{
		Config cfg ( "odict" );
		cfg.setGroup( "Method_"+list->selectedItem()->text(0) );
		cfg.clearGroup();
		//FIXME: this only removes the entries but not the group itself

		list->takeItem( list->selectedItem() );
	}
}

void ConfigDlg::loadSearchMethodNames()
{
	Config cfg(  "odict" );
	QStringList groupListCfg = cfg.groupList().grep( "Method_" );
	for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it )
	{
		cfg.setGroup( *it );
		QString name = cfg.readEntry( "Name" );
		if ( name != QString::null ) {
			QListViewItem *item = new QListViewItem( list );
			item->setText( 0 , name );
		}
	}
}