00001 #include <stdio.h>
00002 #include <stdlib.h>
00003
00004 #include <qfile.h>
00005 #include <qhbox.h>
00006
00007
00008 #include "emulation_handler.h"
00009 #include "metafactory.h"
00010 #include "profileconfig.h"
00011 #include "profilemanager.h"
00012
00013 ProfileManager::ProfileManager( MetaFactory* fact )
00014 : m_fact( fact )
00015 {
00016
00017 }
00018 ProfileManager::~ProfileManager() {
00019
00020 }
00021 void ProfileManager::load() {
00022 m_list.clear();
00023 ProfileConfig conf("opie-console-profiles");
00024 QStringList groups = conf.groups();
00025 QStringList::Iterator it;
00026
00027
00028
00029
00030 for ( it = groups.begin(); it != groups.end(); ++it ) {
00031 conf.setGroup( (*it) );
00032 Profile prof;
00033 prof.setName( conf.readEntry("name") );
00034 prof.setIOLayer( conf.readEntry("iolayer").utf8() );
00035 prof.setTerminalName( conf.readEntry("term").utf8() );
00036 prof.setAutoConnect( conf.readBoolEntry("autoConnect") );
00037 prof.setBackground( conf.readNumEntry("back") );
00038 prof.setForeground( conf.readNumEntry("fore") );
00039 prof.setTerminal( conf.readNumEntry("terminal") );
00040
00041
00042 prof.setConf( conf.items( (*it) ) );
00043
00044
00045 m_list.append( prof );
00046 }
00047
00048 }
00049 void ProfileManager::clear() {
00050 m_list.clear();
00051 }
00052 Profile::ValueList ProfileManager::all()const {
00053 return m_list;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) {
00069
00070
00071
00072
00073
00074
00075
00076
00077 Session* session = new Session();
00078 session->setName( prof.name() );
00079
00080 session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) ,
00081 prof) );
00082
00083 QWidgetStack *stack = new QWidgetStack( parent );
00084 session->setWidgetStack( stack );
00085 QWidget* dummy = new QHBox( stack );
00086 stack->raiseWidget( dummy );
00087
00088 EmulationHandler* handler = new EmulationHandler(prof,dummy );
00089 session->setEmulationHandler( handler );
00090 session->connect();
00091 session->setProfile( prof );
00092
00093 return session;
00094 }
00095 void ProfileManager::save( ) {
00096 QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) );
00097 ProfileConfig conf("opie-console-profiles");
00098 Profile::ValueList::Iterator it2;
00099 for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
00100 conf.setGroup( (*it2).name() );
00101
00102
00103 QMap<QString, QString> map = (*it2).conf();
00104 QMap<QString, QString>::Iterator confIt;
00105 for ( confIt = map.begin(); confIt != map.end(); ++confIt ) {
00106 conf.writeEntry( confIt.key(), confIt.data() );
00107 }
00108
00109 conf.writeEntry( "name", (*it2).name() );
00110 QString str = QString::fromUtf8( (*it2).ioLayerName() );
00111
00112 conf.writeEntry( "iolayer", str );
00113 conf.writeEntry( "term", QString::fromUtf8( (*it2).terminalName() ) );
00114 conf.writeEntry( "autoConnect", (*it2).autoConnect());
00115 conf.writeEntry( "back", (*it2).background() );
00116 conf.writeEntry( "fore", (*it2).foreground() );
00117 conf.writeEntry( "terminal", (*it2).terminal() );
00118 }
00119 }
00120 void ProfileManager::add( const Profile& prof) {
00121 m_list.append( prof );
00122 }
00123 void ProfileManager::setProfiles( const Profile::ValueList& list ) {
00124 m_list = list;
00125 };
00126 Profile ProfileManager::profile( const QString& name )const {
00127 Profile prof;
00128 Profile::ValueList::ConstIterator it;
00129 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
00130 if ( name == (*it).name() ) {
00131 prof = (*it);
00132 break;
00133 }
00134 }
00135 return prof;
00136 }