summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/configdialog.cpp
blob: 882cd3dca2906812e3dcee164704bcbfec710530 (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
108
109
110
111

#include <qpe/qpeapplication.h>

#include <qlistview.h>

#include "configdialog.h"
#include "profileeditordialog.h"

class ConfigListItem : public QListViewItem {
public:
    ConfigListItem( QListView* item, const Profile& );
    ~ConfigListItem();
    Profile profile()const;

private:
    Profile m_prof;
};
ConfigListItem::ConfigListItem( QListView* item, const Profile& prof )
    : QListViewItem( item ), m_prof( prof )
{
    setText(0, prof.name() );
}
ConfigListItem::~ConfigListItem() {

}
Profile ConfigListItem::profile()const {
    return m_prof;
}

/* Dialog */

ConfigDialog::ConfigDialog( const Profile::ValueList& lis, MetaFactory* fa,
                            QWidget* parent )
    : ConfigureBase( parent, 0, TRUE ), m_fact( fa )
{
    //init();
    {
        Profile::ValueList::ConstIterator it;
        for (it = lis.begin(); it != lis.end(); ++it ) {
            new ConfigListItem( lstView, (*it) );
        }
    }
}
ConfigDialog::~ConfigDialog() {

}
Profile::ValueList ConfigDialog::list()const {
/* iterate over the list */
    Profile::ValueList lst;
    QListViewItemIterator it(lstView);
    for ( ; it.current(); ++it ) {
        ConfigListItem* item = (ConfigListItem*)it.current();
        lst.append( item->profile() );
    }
    return lst;
}
/* our slots */
void ConfigDialog::slotRemove() {
    ConfigListItem* item = (ConfigListItem*)lstView->currentItem();
    if (!item )
        return;

    lstView->takeItem( item );
    delete item;
}

void ConfigDialog::slotEdit() {
	Profile p;

	if(!lstView->currentItem()) return;

	// Load profile
	p = ((ConfigListItem*)lstView->currentItem())->profile();

	ProfileEditorDialog dlg(m_fact, p);

	dlg.setCaption(tr("Edit Connection Profile"));
	int ret = QPEApplication::execDialog( &dlg );

	if(ret == QDialog::Accepted)
	{
		if(lstView->currentItem()) delete lstView->currentItem();

		// use dlg.terminal()!
		Profile p = dlg.profile();

		new ConfigListItem(lstView, p);
	}
}


void ConfigDialog::slotAdd() {
	ProfileEditorDialog dlg(m_fact);

	dlg.setCaption(tr("New Connection"));
	int ret = QPEApplication::execDialog( &dlg );

	if(ret == QDialog::Accepted)
	{
		// TODO: Move into general profile save part
		// assignments
		//QString type = dlg.term_type();
		//if(type == "VT102") profile = Profile::VT102;

		// get profile from editor
		Profile p = dlg.profile();

		new ConfigListItem(lstView, p);
	}
}