-rw-r--r-- | noncore/apps/opie-console/profile.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/profile.h | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/profilemanager.cpp | 23 |
3 files changed, 26 insertions, 6 deletions
diff --git a/noncore/apps/opie-console/profile.cpp b/noncore/apps/opie-console/profile.cpp index cdf595e..c8f5eb0 100644 --- a/noncore/apps/opie-console/profile.cpp +++ b/noncore/apps/opie-console/profile.cpp | |||
@@ -1,106 +1,112 @@ | |||
1 | #include "profile.h" | 1 | #include "profile.h" |
2 | 2 | ||
3 | Profile::Profile() { | 3 | Profile::Profile() { |
4 | 4 | ||
5 | } | 5 | } |
6 | Profile::Profile( const QString& name, | 6 | Profile::Profile( const QString& name, |
7 | const QString& iolayerName, | 7 | const QString& iolayerName, |
8 | int background, | 8 | int background, |
9 | int foreground, | 9 | int foreground, |
10 | int terminal ) | 10 | int terminal ) |
11 | : m_name( name ), m_ioLayer( iolayerName ), m_back( background ), | 11 | : m_name( name ), m_ioLayer( iolayerName ), m_back( background ), |
12 | m_fore( foreground ), m_terminal( terminal ) | 12 | m_fore( foreground ), m_terminal( terminal ) |
13 | { | 13 | { |
14 | } | 14 | } |
15 | Profile::Profile( const Profile& prof ) | 15 | Profile::Profile( const Profile& prof ) |
16 | { | 16 | { |
17 | (*this) = prof; | 17 | (*this) = prof; |
18 | } | 18 | } |
19 | bool Profile::operator==( const Profile& prof ) { | 19 | bool Profile::operator==( const Profile& prof ) { |
20 | if ( m_name == prof.m_name ) return true; | 20 | if ( m_name == prof.m_name ) return true; |
21 | 21 | ||
22 | return false; | 22 | return false; |
23 | } | 23 | } |
24 | Profile &Profile::operator=( const Profile& prof ) { | 24 | Profile &Profile::operator=( const Profile& prof ) { |
25 | m_name = prof.m_name; | 25 | m_name = prof.m_name; |
26 | m_ioLayer = prof.m_ioLayer; | 26 | m_ioLayer = prof.m_ioLayer; |
27 | m_back = prof.m_back; | 27 | m_back = prof.m_back; |
28 | m_fore = prof.m_fore; | 28 | m_fore = prof.m_fore; |
29 | m_terminal = prof.m_terminal; | 29 | m_terminal = prof.m_terminal; |
30 | m_conf = prof.m_conf; | 30 | m_conf = prof.m_conf; |
31 | 31 | ||
32 | return *this; | 32 | return *this; |
33 | } | 33 | } |
34 | Profile::~Profile() { | 34 | Profile::~Profile() { |
35 | } | 35 | } |
36 | QMap<QString, QString> Profile::conf()const { | ||
37 | return m_conf; | ||
38 | } | ||
36 | QString Profile::name()const { | 39 | QString Profile::name()const { |
37 | return m_name; | 40 | return m_name; |
38 | } | 41 | } |
39 | QString Profile::ioLayerName()const { | 42 | QString Profile::ioLayerName()const { |
40 | return m_ioLayer; | 43 | return m_ioLayer; |
41 | } | 44 | } |
42 | int Profile::foreground()const { | 45 | int Profile::foreground()const { |
43 | return m_fore; | 46 | return m_fore; |
44 | } | 47 | } |
45 | int Profile::background()const { | 48 | int Profile::background()const { |
46 | return m_back; | 49 | return m_back; |
47 | } | 50 | } |
48 | int Profile::terminal()const { | 51 | int Profile::terminal()const { |
49 | return m_terminal; | 52 | return m_terminal; |
50 | } | 53 | } |
51 | void Profile::setName( const QString& str ) { | 54 | void Profile::setName( const QString& str ) { |
52 | m_name = str; | 55 | m_name = str; |
53 | } | 56 | } |
54 | void Profile::setIOLayer( const QString& name ) { | 57 | void Profile::setIOLayer( const QString& name ) { |
55 | m_ioLayer = name; | 58 | m_ioLayer = name; |
56 | } | 59 | } |
57 | void Profile::setBackground( int back ) { | 60 | void Profile::setBackground( int back ) { |
58 | m_back = back; | 61 | m_back = back; |
59 | } | 62 | } |
60 | void Profile::setForeground( int fore ) { | 63 | void Profile::setForeground( int fore ) { |
61 | m_fore = fore; | 64 | m_fore = fore; |
62 | } | 65 | } |
63 | void Profile::setTerminal( int term ) { | 66 | void Profile::setTerminal( int term ) { |
64 | m_terminal = term; | 67 | m_terminal = term; |
65 | } | 68 | } |
66 | /* config stuff */ | 69 | /* config stuff */ |
67 | void Profile::clearConf() { | 70 | void Profile::clearConf() { |
68 | m_conf.clear(); | 71 | m_conf.clear(); |
69 | } | 72 | } |
70 | void Profile::writeEntry( const QString& key, const QString& value ) { | 73 | void Profile::writeEntry( const QString& key, const QString& value ) { |
71 | m_conf.replace( key, value ); | 74 | m_conf.replace( key, value ); |
72 | } | 75 | } |
73 | void Profile::writeEntry( const QString& key, int num ) { | 76 | void Profile::writeEntry( const QString& key, int num ) { |
74 | writeEntry( key, QString::number( num ) ); | 77 | writeEntry( key, QString::number( num ) ); |
75 | } | 78 | } |
76 | void Profile::writeEntry( const QString& key, bool b ) { | 79 | void Profile::writeEntry( const QString& key, bool b ) { |
77 | writeEntry( key, QString::number(b) ); | 80 | writeEntry( key, QString::number(b) ); |
78 | } | 81 | } |
79 | void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) { | 82 | void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) { |
80 | writeEntry( key, lis.join(sep) ); | 83 | writeEntry( key, lis.join(sep) ); |
81 | } | 84 | } |
82 | QString Profile::readEntry( const QString& key, const QString& deflt )const { | 85 | QString Profile::readEntry( const QString& key, const QString& deflt )const { |
83 | QMap<QString, QString>::ConstIterator it; | 86 | QMap<QString, QString>::ConstIterator it; |
84 | it = m_conf.find( key ); | 87 | it = m_conf.find( key ); |
85 | 88 | ||
86 | if ( it != m_conf.end() ) | 89 | if ( it != m_conf.end() ) |
87 | return it.data(); | 90 | return it.data(); |
88 | 91 | ||
89 | return deflt; | 92 | return deflt; |
90 | } | 93 | } |
91 | int Profile::readNumEntry( const QString& key, int def )const { | 94 | int Profile::readNumEntry( const QString& key, int def )const { |
92 | QMap<QString, QString>::ConstIterator it; | 95 | QMap<QString, QString>::ConstIterator it; |
93 | it = m_conf.find( key ); | 96 | it = m_conf.find( key ); |
94 | 97 | ||
95 | if ( it != m_conf.end() ) { | 98 | if ( it != m_conf.end() ) { |
96 | bool ok; | 99 | bool ok; |
97 | int val = it.data().toInt(&ok); | 100 | int val = it.data().toInt(&ok); |
98 | 101 | ||
99 | if (ok) | 102 | if (ok) |
100 | return val; | 103 | return val; |
101 | } | 104 | } |
102 | return def; | 105 | return def; |
103 | } | 106 | } |
104 | bool Profile::readBoolEntry( const QString& key, bool def )const { | 107 | bool Profile::readBoolEntry( const QString& key, bool def )const { |
105 | return readNumEntry( key, def ); | 108 | return readNumEntry( key, def ); |
106 | } | 109 | } |
110 | void Profile::setConf( const QMap<QString, QString>& conf ) { | ||
111 | m_conf = conf; | ||
112 | }; | ||
diff --git a/noncore/apps/opie-console/profile.h b/noncore/apps/opie-console/profile.h index eff2be1..9956bdb 100644 --- a/noncore/apps/opie-console/profile.h +++ b/noncore/apps/opie-console/profile.h | |||
@@ -1,67 +1,68 @@ | |||
1 | #ifndef OPIE_PROFILE_H | 1 | #ifndef OPIE_PROFILE_H |
2 | #define OPIE_PROFILE_H | 2 | #define OPIE_PROFILE_H |
3 | 3 | ||
4 | #include <qmap.h> | 4 | #include <qmap.h> |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | #include <qvaluelist.h> | 7 | #include <qvaluelist.h> |
8 | /** | 8 | /** |
9 | * A session will be generated from a saved | 9 | * A session will be generated from a saved |
10 | * profile. A profile contains the iolayername | 10 | * profile. A profile contains the iolayername |
11 | * a name. | 11 | * a name. |
12 | * We can generate a Session from a Profile | 12 | * We can generate a Session from a Profile |
13 | * No configuration is contained here.... | 13 | * No configuration is contained here.... |
14 | */ | 14 | */ |
15 | class Profile { | 15 | class Profile { |
16 | public: | 16 | public: |
17 | typedef QValueList<Profile> ValueList; | 17 | typedef QValueList<Profile> ValueList; |
18 | enum Color { Black = 0, | 18 | enum Color { Black = 0, |
19 | White, | 19 | White, |
20 | Gray }; | 20 | Gray }; |
21 | enum Terminal {VT102 = 0 }; | 21 | enum Terminal {VT102 = 0 }; |
22 | enum Font { Micro = 0, Small, Medium }; | 22 | enum Font { Micro = 0, Small, Medium }; |
23 | Profile(); | 23 | Profile(); |
24 | Profile( const QString& name, | 24 | Profile( const QString& name, |
25 | const QString& iolayerName, | 25 | const QString& iolayerName, |
26 | int background, | 26 | int background, |
27 | int foreground, | 27 | int foreground, |
28 | int terminal); | 28 | int terminal); |
29 | Profile( const Profile& ); | 29 | Profile( const Profile& ); |
30 | Profile &operator=( const Profile& ); | 30 | Profile &operator=( const Profile& ); |
31 | bool operator==( const Profile& prof ); | 31 | bool operator==( const Profile& prof ); |
32 | 32 | ||
33 | ~Profile(); | 33 | ~Profile(); |
34 | QString name()const; | 34 | QString name()const; |
35 | QString ioLayerName()const; | 35 | QString ioLayerName()const; |
36 | int foreground()const; | 36 | int foreground()const; |
37 | int background()const; | 37 | int background()const; |
38 | int terminal()const; | 38 | int terminal()const; |
39 | 39 | ||
40 | /* | 40 | /* |
41 | * config stuff | 41 | * config stuff |
42 | */ | 42 | */ |
43 | QMap<QString, QString> conf(); | 43 | QMap<QString, QString> conf()const; |
44 | void clearConf(); | 44 | void clearConf(); |
45 | void writeEntry( const QString& key, const QString& value ); | 45 | void writeEntry( const QString& key, const QString& value ); |
46 | void writeEntry( const QString& key, int num ); | 46 | void writeEntry( const QString& key, int num ); |
47 | void writeEntry( const QString& key, bool b ); | 47 | void writeEntry( const QString& key, bool b ); |
48 | void writeEntry( const QString& key, const QStringList&, const QChar& ); | 48 | void writeEntry( const QString& key, const QStringList&, const QChar& ); |
49 | QString readEntry( const QString& key, const QString& deflt = QString::null)const; | 49 | QString readEntry( const QString& key, const QString& deflt = QString::null)const; |
50 | int readNumEntry( const QString& key, int = -1 )const; | 50 | int readNumEntry( const QString& key, int = -1 )const; |
51 | bool readBoolEntry( const QString& key, bool = FALSE )const; | 51 | bool readBoolEntry( const QString& key, bool = FALSE )const; |
52 | 52 | ||
53 | void setName( const QString& ); | 53 | void setName( const QString& ); |
54 | void setIOLayer( const QString& ); | 54 | void setIOLayer( const QString& ); |
55 | void setBackground( int back ); | 55 | void setBackground( int back ); |
56 | void setForeground( int fore ); | 56 | void setForeground( int fore ); |
57 | void setTerminal( int term ); | 57 | void setTerminal( int term ); |
58 | void setConf( const QMap<QString, QString>& ); | ||
58 | private: | 59 | private: |
59 | QMap<QString, QString> m_conf; | 60 | QMap<QString, QString> m_conf; |
60 | QString m_name; | 61 | QString m_name; |
61 | QString m_ioLayer; | 62 | QString m_ioLayer; |
62 | int m_back; | 63 | int m_back; |
63 | int m_fore; | 64 | int m_fore; |
64 | int m_terminal; | 65 | int m_terminal; |
65 | }; | 66 | }; |
66 | 67 | ||
67 | #endif | 68 | #endif |
diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp index 54b184d..c8a4db5 100644 --- a/noncore/apps/opie-console/profilemanager.cpp +++ b/noncore/apps/opie-console/profilemanager.cpp | |||
@@ -1,65 +1,78 @@ | |||
1 | 1 | ||
2 | #include <qpe/config.h> | 2 | #include <qpe/config.h> |
3 | 3 | ||
4 | #include "metafactory.h" | 4 | #include "metafactory.h" |
5 | #include "profileconfig.h" | 5 | #include "profileconfig.h" |
6 | #include "profilemanager.h" | 6 | #include "profilemanager.h" |
7 | 7 | ||
8 | ProfileManager::ProfileManager( MetaFactory* fact ) | 8 | ProfileManager::ProfileManager( MetaFactory* fact ) |
9 | : m_fact( fact ) | 9 | : m_fact( fact ) |
10 | { | 10 | { |
11 | 11 | ||
12 | } | 12 | } |
13 | ProfileManager::~ProfileManager() { | 13 | ProfileManager::~ProfileManager() { |
14 | 14 | ||
15 | } | 15 | } |
16 | void ProfileManager::load() { | 16 | void ProfileManager::load() { |
17 | m_list.clear(); | 17 | m_list.clear(); |
18 | ProfileConfig conf("opie-console-profiles"); | 18 | ProfileConfig conf("opie-console-profiles"); |
19 | QStringList groups = conf.groups(); | 19 | QStringList groups = conf.groups(); |
20 | QStringList::Iterator it; | 20 | QStringList::Iterator it; |
21 | 21 | ||
22 | /* | 22 | /* |
23 | * for each profile | 23 | * for each profile |
24 | */ | 24 | */ |
25 | /* | ||
26 | * QAsciiDict Parsing FIXME | ||
27 | */ | ||
28 | for ( it = groups.begin(); it != groups.end(); ++it ) { | 25 | for ( it = groups.begin(); it != groups.end(); ++it ) { |
29 | conf.setGroup( (*it) ); | 26 | conf.setGroup( (*it) ); |
30 | Profile prof; | 27 | Profile prof; |
31 | prof.setName( conf.readEntry("name") ); | 28 | prof.setName( conf.readEntry("name") ); |
32 | prof.setIOLayer( conf.readEntry("iolayer") ); | 29 | prof.setIOLayer( conf.readEntry("iolayer") ); |
33 | prof.setBackground( conf.readNumEntry("back") ); | 30 | prof.setBackground( conf.readNumEntry("back") ); |
34 | prof.setForeground( conf.readNumEntry("fore") ); | 31 | prof.setForeground( conf.readNumEntry("fore") ); |
35 | prof.setTerminal( conf.readNumEntry("terminal") ); | 32 | prof.setTerminal( conf.readNumEntry("terminal") ); |
33 | prof.setConf( conf.items( (*it) ) ); | ||
36 | 34 | ||
35 | /* now add it */ | ||
37 | m_list.append( prof ); | 36 | m_list.append( prof ); |
38 | } | 37 | } |
39 | 38 | ||
40 | } | 39 | } |
41 | void ProfileManager::clear() { | 40 | void ProfileManager::clear() { |
42 | m_list.clear(); | 41 | m_list.clear(); |
43 | } | 42 | } |
44 | Profile::ValueList ProfileManager::all()const { | 43 | Profile::ValueList ProfileManager::all()const { |
45 | return m_list; | 44 | return m_list; |
46 | } | 45 | } |
47 | Session* ProfileManager::fromProfile( const Profile& prof) { | 46 | Session* ProfileManager::fromProfile( const Profile& prof) { |
48 | Session* session = new Session(); | 47 | Session* session = new Session(); |
49 | session->setName( prof.name() ); | 48 | session->setName( prof.name() ); |
50 | session->setIOLayer(m_fact->newIOLayer(prof.ioLayerName(), | 49 | session->setIOLayer(m_fact->newIOLayer(prof.ioLayerName(), |
51 | prof) ); | 50 | prof) ); |
52 | /* | 51 | /* |
53 | * FIXME | 52 | * FIXME |
54 | * load emulation | 53 | * load emulation |
55 | * load widget | 54 | * load widget? |
56 | * set colors + fonts | 55 | * set colors + fonts |
57 | */ | 56 | */ |
58 | return session; | 57 | return session; |
59 | } | 58 | } |
60 | void ProfileManager::save( ) { | 59 | void ProfileManager::save( ) { |
61 | ProfileConfig conf("opie-console-profiles"); | 60 | ProfileConfig conf("opie-console-profiles"); |
62 | conf.clearAll(); | 61 | conf.clearAll(); |
63 | Session* se= 0l; | 62 | Profile::ValueList::Iterator it; |
63 | for (it = m_list.begin(); it != m_list.end(); ++it ) { | ||
64 | conf.setGroup( (*it).name() ); | ||
65 | conf.writeEntry( "name", (*it).name() ); | ||
66 | conf.writeEntry( "ioplayer", (*it).ioLayerName() ); | ||
67 | conf.writeEntry( "back", (*it).background() ); | ||
68 | conf.writeEntry( "fore", (*it).foreground() ); | ||
69 | conf.writeEntry( "terminal", (*it).terminal() ); | ||
70 | /* now the config stuff */ | ||
71 | QMap<QString, QString> map = (*it).conf(); | ||
72 | QMap<QString, QString>::Iterator it; | ||
73 | for ( it = map.begin(); it != map.end(); ++it ) { | ||
74 | conf.writeEntry( it.key(), it.data() ); | ||
75 | } | ||
76 | } | ||
64 | // FIXME save | 77 | // FIXME save |
65 | } | 78 | } |