-rw-r--r-- | noncore/apps/opie-console/profilemanager.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp index c965700..4b88dec 100644 --- a/noncore/apps/opie-console/profilemanager.cpp +++ b/noncore/apps/opie-console/profilemanager.cpp | |||
@@ -1,127 +1,134 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | 3 | ||
4 | #include <qfile.h> | 4 | #include <qfile.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | #include <qwidgetstack.h> | 6 | #include <qwidgetstack.h> |
7 | 7 | ||
8 | #include <qpe/config.h> | 8 | #include <qpe/config.h> |
9 | 9 | ||
10 | #include "widget_layer.h" | 10 | #include "widget_layer.h" |
11 | #include "emulation_widget.h" | 11 | #include "emulation_widget.h" |
12 | #include "metafactory.h" | 12 | #include "metafactory.h" |
13 | #include "profileconfig.h" | 13 | #include "profileconfig.h" |
14 | #include "profilemanager.h" | 14 | #include "profilemanager.h" |
15 | 15 | ||
16 | ProfileManager::ProfileManager( MetaFactory* fact ) | 16 | ProfileManager::ProfileManager( MetaFactory* fact ) |
17 | : m_fact( fact ) | 17 | : m_fact( fact ) |
18 | { | 18 | { |
19 | 19 | ||
20 | } | 20 | } |
21 | ProfileManager::~ProfileManager() { | 21 | ProfileManager::~ProfileManager() { |
22 | 22 | ||
23 | } | 23 | } |
24 | void ProfileManager::load() { | 24 | void ProfileManager::load() { |
25 | m_list.clear(); | 25 | m_list.clear(); |
26 | qWarning("load"); | 26 | qWarning("load"); |
27 | ProfileConfig conf("opie-console-profiles"); | 27 | ProfileConfig conf("opie-console-profiles"); |
28 | QStringList groups = conf.groups(); | 28 | QStringList groups = conf.groups(); |
29 | QStringList::Iterator it; | 29 | QStringList::Iterator it; |
30 | 30 | ||
31 | /* | 31 | /* |
32 | * for each profile | 32 | * for each profile |
33 | */ | 33 | */ |
34 | for ( it = groups.begin(); it != groups.end(); ++it ) { | 34 | for ( it = groups.begin(); it != groups.end(); ++it ) { |
35 | qWarning("group " + (*it) ); | 35 | qWarning("group " + (*it) ); |
36 | conf.setGroup( (*it) ); | 36 | conf.setGroup( (*it) ); |
37 | Profile prof; | 37 | Profile prof; |
38 | prof.setName( conf.readEntry("name") ); | 38 | prof.setName( conf.readEntry("name") ); |
39 | prof.setIOLayer( conf.readEntry("iolayer").utf8() ); | 39 | prof.setIOLayer( conf.readEntry("iolayer").utf8() ); |
40 | prof.setTerminalName( conf.readEntry("term").utf8() ); | 40 | prof.setTerminalName( conf.readEntry("term").utf8() ); |
41 | qWarning(" %s %s", conf.readEntry("iolayer").latin1(), prof.ioLayerName().data() ); | 41 | qWarning(" %s %s", conf.readEntry("iolayer").latin1(), prof.ioLayerName().data() ); |
42 | prof.setBackground( conf.readNumEntry("back") ); | 42 | prof.setBackground( conf.readNumEntry("back") ); |
43 | prof.setForeground( conf.readNumEntry("fore") ); | 43 | prof.setForeground( conf.readNumEntry("fore") ); |
44 | prof.setTerminal( conf.readNumEntry("terminal") ); | 44 | prof.setTerminal( conf.readNumEntry("terminal") ); |
45 | |||
46 | // THIS is evil because all data get's reset | ||
45 | prof.setConf( conf.items( (*it) ) ); | 47 | prof.setConf( conf.items( (*it) ) ); |
46 | 48 | ||
47 | /* now add it */ | 49 | /* now add it */ |
48 | m_list.append( prof ); | 50 | m_list.append( prof ); |
49 | } | 51 | } |
50 | 52 | ||
51 | } | 53 | } |
52 | void ProfileManager::clear() { | 54 | void ProfileManager::clear() { |
53 | m_list.clear(); | 55 | m_list.clear(); |
54 | } | 56 | } |
55 | Profile::ValueList ProfileManager::all()const { | 57 | Profile::ValueList ProfileManager::all()const { |
56 | return m_list; | 58 | return m_list; |
57 | } | 59 | } |
58 | /* | 60 | /* |
59 | * Our goal is to create a Session | 61 | * Our goal is to create a Session |
60 | * We will load the the IOLayer and EmulationLayer | 62 | * We will load the the IOLayer and EmulationLayer |
61 | * from the factory | 63 | * from the factory |
62 | * we will generate a QWidgetStack | 64 | * we will generate a QWidgetStack |
63 | * add a dummy widget with layout | 65 | * add a dummy widget with layout |
64 | * add "Widget" to the layout | 66 | * add "Widget" to the layout |
65 | * add the dummy to the stack | 67 | * add the dummy to the stack |
66 | * raise the dummy | 68 | * raise the dummy |
67 | * call session->connect(= | 69 | * call session->connect(= |
68 | * this way we only need to reparent | 70 | * this way we only need to reparent |
69 | * in TabWidget | 71 | * in TabWidget |
70 | */ | 72 | */ |
71 | Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) { | 73 | Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) { |
72 | Session* session = new Session(); | 74 | Session* session = new Session(); |
73 | session->setName( prof.name() ); | 75 | session->setName( prof.name() ); |
74 | /* translate the internal name to the external */ | 76 | /* translate the internal name to the external */ |
75 | session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) , | 77 | session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) , |
76 | prof) ); | 78 | prof) ); |
77 | 79 | ||
78 | QWidgetStack *stack = new QWidgetStack(parent); | 80 | QWidgetStack *stack = new QWidgetStack(parent); |
79 | session->setWidgetStack( stack ); | 81 | session->setWidgetStack( stack ); |
80 | QWidget* dummy = new QWidget( stack ); | 82 | QWidget* dummy = new QWidget( stack ); |
81 | QHBoxLayout* lay = new QHBoxLayout(dummy ); | 83 | QHBoxLayout* lay = new QHBoxLayout(dummy ); |
82 | stack->addWidget( dummy, 0 ); | 84 | stack->addWidget( dummy, 0 ); |
83 | stack->raiseWidget( 0 ); | 85 | stack->raiseWidget( 0 ); |
84 | WidgetLayer* wid = new EmulationWidget( prof, dummy ); | 86 | WidgetLayer* wid = new EmulationWidget( prof, dummy ); |
85 | lay->addWidget( wid ); | 87 | lay->addWidget( wid ); |
86 | 88 | ||
87 | session->setEmulationWidget( wid ); | 89 | session->setEmulationWidget( wid ); |
88 | session->setEmulationLayer( m_fact->newEmulationLayer( m_fact->external( prof.terminalName() ), | 90 | session->setEmulationLayer( m_fact->newEmulationLayer( m_fact->external( prof.terminalName() ), |
89 | wid ) ); | 91 | wid ) ); |
90 | session->connect(); | 92 | session->connect(); |
91 | 93 | ||
92 | return session; | 94 | return session; |
93 | } | 95 | } |
94 | void ProfileManager::save( ) { | 96 | void ProfileManager::save( ) { |
95 | QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) ); | 97 | QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) ); |
96 | ProfileConfig conf("opie-console-profiles"); | 98 | ProfileConfig conf("opie-console-profiles"); |
97 | Profile::ValueList::Iterator it; | 99 | Profile::ValueList::Iterator it2; |
98 | for (it = m_list.begin(); it != m_list.end(); ++it ) { | 100 | for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { |
99 | conf.setGroup( (*it).name() ); | 101 | conf.setGroup( (*it2).name() ); |
100 | conf.writeEntry( "name", (*it).name() ); | 102 | |
101 | conf.writeEntry( "iolayer", QString::fromUtf8( (*it).ioLayerName() ) ); | ||
102 | conf.writeEntry( "term", QString::fromUtf8( (*it).terminalName() ) ); | ||
103 | conf.writeEntry( "back", (*it).background() ); | ||
104 | conf.writeEntry( "fore", (*it).foreground() ); | ||
105 | conf.writeEntry( "terminal", (*it).terminal() ); | ||
106 | /* now the config stuff */ | 103 | /* now the config stuff */ |
107 | QMap<QString, QString> map = (*it).conf(); | 104 | QMap<QString, QString> map = (*it2).conf(); |
108 | QMap<QString, QString>::Iterator it; | 105 | QMap<QString, QString>::Iterator confIt; |
109 | for ( it = map.begin(); it != map.end(); ++it ) { | 106 | for ( confIt = map.begin(); confIt != map.end(); ++confIt ) { |
110 | conf.writeEntry( it.key(), it.data() ); | 107 | conf.writeEntry( confIt.key(), confIt.data() ); |
111 | } | 108 | } |
109 | |||
110 | conf.writeEntry( "name", (*it2).name() ); | ||
111 | QString str = QString::fromUtf8( (*it2).ioLayerName() ); | ||
112 | qWarning("IOLayerName " + str ); | ||
113 | |||
114 | conf.writeEntry( "iolayer", str ); | ||
115 | conf.writeEntry( "term", QString::fromUtf8( (*it2).terminalName() ) ); | ||
116 | conf.writeEntry( "back", (*it2).background() ); | ||
117 | conf.writeEntry( "fore", (*it2).foreground() ); | ||
118 | conf.writeEntry( "terminal", (*it2).terminal() ); | ||
112 | } | 119 | } |
113 | } | 120 | } |
114 | void ProfileManager::setProfiles( const Profile::ValueList& list ) { | 121 | void ProfileManager::setProfiles( const Profile::ValueList& list ) { |
115 | m_list = list; | 122 | m_list = list; |
116 | }; | 123 | }; |
117 | Profile ProfileManager::profile( const QString& name )const { | 124 | Profile ProfileManager::profile( const QString& name )const { |
118 | Profile prof; | 125 | Profile prof; |
119 | Profile::ValueList::ConstIterator it; | 126 | Profile::ValueList::ConstIterator it; |
120 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { | 127 | for ( it = m_list.begin(); it != m_list.end(); ++it ) { |
121 | if ( name == (*it).name() ) { | 128 | if ( name == (*it).name() ) { |
122 | prof = (*it); | 129 | prof = (*it); |
123 | break; | 130 | break; |
124 | } | 131 | } |
125 | } | 132 | } |
126 | return prof; | 133 | return prof; |
127 | } | 134 | } |