00001
00002 #include <qpe/qpeapplication.h>
00003
00004 #include <qlistview.h>
00005
00006 #include "configdialog.h"
00007 #include "profileeditordialog.h"
00008
00009 class ConfigListItem : public QListViewItem {
00010 public:
00011 ConfigListItem( QListView* item, const Profile& );
00012 ~ConfigListItem();
00013 Profile profile()const;
00014
00015 private:
00016 Profile m_prof;
00017 };
00018 ConfigListItem::ConfigListItem( QListView* item, const Profile& prof )
00019 : QListViewItem( item ), m_prof( prof )
00020 {
00021 setText(0, prof.name() );
00022 }
00023 ConfigListItem::~ConfigListItem() {
00024
00025 }
00026 Profile ConfigListItem::profile()const {
00027 return m_prof;
00028 }
00029
00030
00031
00032 ConfigDialog::ConfigDialog( const Profile::ValueList& lis, MetaFactory* fa,
00033 QWidget* parent )
00034 : ConfigureBase( parent, 0, TRUE ), m_fact( fa )
00035 {
00036
00037 {
00038 Profile::ValueList::ConstIterator it;
00039 for (it = lis.begin(); it != lis.end(); ++it ) {
00040 new ConfigListItem( lstView, (*it) );
00041 }
00042 }
00043 }
00044 ConfigDialog::~ConfigDialog() {
00045
00046 }
00047 Profile::ValueList ConfigDialog::list()const {
00048
00049 Profile::ValueList lst;
00050 QListViewItemIterator it(lstView);
00051 for ( ; it.current(); ++it ) {
00052 ConfigListItem* item = (ConfigListItem*)it.current();
00053 lst.append( item->profile() );
00054 }
00055 return lst;
00056 }
00057
00058 void ConfigDialog::slotRemove() {
00059 ConfigListItem* item = (ConfigListItem*)lstView->currentItem();
00060 if (!item )
00061 return;
00062
00063 lstView->takeItem( item );
00064 delete item;
00065 }
00066
00067 void ConfigDialog::slotEdit() {
00068 Profile p;
00069
00070 if(!lstView->currentItem()) return;
00071
00072
00073 p = ((ConfigListItem*)lstView->currentItem())->profile();
00074
00075 ProfileEditorDialog dlg(m_fact, p);
00076
00077 dlg.setCaption(tr("Edit Connection Profile"));
00078 int ret = QPEApplication::execDialog( &dlg );
00079
00080 if(ret == QDialog::Accepted)
00081 {
00082 if(lstView->currentItem()) delete lstView->currentItem();
00083
00084
00085 Profile p = dlg.profile();
00086
00087 new ConfigListItem(lstView, p);
00088 }
00089 }
00090
00091
00092 void ConfigDialog::slotAdd() {
00093 ProfileEditorDialog dlg(m_fact);
00094
00095 dlg.setCaption(tr("New Connection"));
00096 int ret = QPEApplication::execDialog( &dlg );
00097
00098 if(ret == QDialog::Accepted)
00099 {
00100
00101
00102
00103
00104
00105
00106 Profile p = dlg.profile();
00107
00108 new ConfigListItem(lstView, p);
00109 }
00110 }
00111