00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "SessionManager.h"
00024
00025
00026 #include <QtCore/QDir>
00027 #include <QtCore/QFileInfo>
00028 #include <QtCore/QList>
00029 #include <QtCore/QSignalMapper>
00030 #include <QtCore/QString>
00031 #include <QtCore/QTextCodec>
00032
00033
00034 #include <klocale.h>
00035 #include <kicon.h>
00036 #include <krun.h>
00037 #include <kshell.h>
00038 #include <kconfig.h>
00039 #include <kglobal.h>
00040 #include <kdebug.h>
00041 #include <kconfiggroup.h>
00042 #include <kstandarddirs.h>
00043 #include <kdesktopfile.h>
00044
00045
00046 #include "ColorScheme.h"
00047 #include "Session.h"
00048 #include "History.h"
00049 #include "ShellCommand.h"
00050
00051 using namespace Konsole;
00052
00053 #if 0
00054
00055 bool Profile::isAvailable() const
00056 {
00057
00058
00059 QString binary = KRun::binaryName( command(true) , false );
00060 binary = KShell::tildeExpand(binary);
00061
00062 QString fullBinaryPath = KGlobal::dirs()->findExe(binary);
00063
00064 if ( fullBinaryPath.isEmpty() )
00065 return false;
00066 else
00067 return true;
00068 }
00069 #endif
00070
00071 SessionManager::SessionManager()
00072 : _loadedAllProfiles(false)
00073 , _loadedFavorites(false)
00074 {
00075
00076 _sessionMapper = new QSignalMapper(this);
00077 connect( _sessionMapper , SIGNAL(mapped(QObject*)) , this ,
00078 SLOT(sessionTerminated(QObject*)) );
00079
00080
00081 _fallbackProfile = Profile::Ptr(new FallbackProfile);
00082 addProfile(_fallbackProfile);
00083
00084
00085 KSharedConfigPtr appConfig = KGlobal::config();
00086 const KConfigGroup group = appConfig->group( "Desktop Entry" );
00087 QString defaultSessionFilename = group.readEntry("DefaultProfile","Shell.profile");
00088
00089 QString path = KGlobal::dirs()->findResource("data","konsole/"+defaultSessionFilename);
00090 if (!path.isEmpty())
00091 {
00092 Profile::Ptr profile = loadProfile(path);
00093 if ( profile )
00094 _defaultProfile = profile;
00095 }
00096
00097 Q_ASSERT( _types.count() > 0 );
00098 Q_ASSERT( _defaultProfile );
00099
00100
00101
00102
00103 loadShortcuts();
00104 }
00105 Profile::Ptr SessionManager::loadProfile(const QString& shortPath)
00106 {
00107
00108 if (shortPath == _fallbackProfile->property<QString>(Profile::Path))
00109 return _fallbackProfile;
00110
00111 QString path = shortPath;
00112
00113
00114 QFileInfo fileInfo(path);
00115 if ( fileInfo.suffix().isEmpty() )
00116 path.append(".profile");
00117 if ( fileInfo.path().isEmpty() || fileInfo.path() == "." )
00118 path.prepend(QString("konsole")+QDir::separator());
00119
00120
00121 if ( !fileInfo.isAbsolute() )
00122 path = KStandardDirs::locate("data",path);
00123
00124
00125 QSetIterator<Profile::Ptr> iter(_types);
00126 while ( iter.hasNext() )
00127 {
00128 Profile::Ptr profile = iter.next();
00129 if ( profile->path() == path )
00130 return profile;
00131 }
00132
00133
00134
00135
00136 static QStack<QString> recursionGuard;
00137 PopStackOnExit<QString> popGuardOnExit(recursionGuard);
00138
00139 if (recursionGuard.contains(path))
00140 {
00141 kWarning() << "Ignoring attempt to load profile recursively from" << path;
00142 return _fallbackProfile;
00143 }
00144 else
00145 recursionGuard.push(path);
00146
00147
00148 ProfileReader* reader = 0;
00149 if ( path.endsWith(".desktop") )
00150 reader = 0;
00151 else
00152 reader = new KDE4ProfileReader;
00153
00154 if (!reader)
00155 {
00156 kWarning() << "Could not create loader to read profile from" << path;
00157 return Profile::Ptr();
00158 }
00159
00160 Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile()));
00161 newProfile->setProperty(Profile::Path,path);
00162
00163 QString parentProfilePath;
00164 bool result = reader->readProfile(path,newProfile,parentProfilePath);
00165
00166 if ( !parentProfilePath.isEmpty() )
00167 {
00168 Profile::Ptr parentProfile = loadProfile(parentProfilePath);
00169 newProfile->setParent(parentProfile);
00170 }
00171
00172 delete reader;
00173
00174 if (!result)
00175 {
00176 kWarning() << "Could not load profile from " << path;
00177 return Profile::Ptr();
00178 }
00179 else
00180 {
00181 addProfile(newProfile);
00182 return newProfile;
00183 }
00184 }
00185 QStringList SessionManager::availableProfilePaths() const
00186 {
00187 KDE3ProfileReader kde3Reader;
00188 KDE4ProfileReader kde4Reader;
00189
00190 QStringList profiles;
00191 profiles += kde3Reader.findProfiles();
00192 profiles += kde4Reader.findProfiles();
00193
00194 return profiles;
00195 }
00196
00197 void SessionManager::loadAllProfiles()
00198 {
00199 if ( _loadedAllProfiles )
00200 return;
00201
00202 QStringList profiles = availableProfilePaths();
00203
00204 QListIterator<QString> iter(profiles);
00205 while (iter.hasNext())
00206 loadProfile(iter.next());
00207
00208 _loadedAllProfiles = true;
00209 }
00210 void SessionManager::saveState()
00211 {
00212
00213 setDefaultProfile( _defaultProfile );
00214
00215
00216 saveShortcuts();
00217
00218
00219 saveFavorites();
00220 }
00221 void SessionManager::closeAll()
00222 {
00223
00224 foreach( Session* session , _sessions )
00225 {
00226 session->close();
00227 }
00228 _sessions.clear();
00229 }
00230 SessionManager::~SessionManager()
00231 {
00232 if (_sessions.count() > 0)
00233 {
00234 kWarning() << "Konsole SessionManager destroyed with sessions still alive";
00235
00236
00237 foreach(Session* session , _sessions)
00238 disconnect(session , 0 , this , 0);
00239 }
00240 }
00241
00242 const QList<Session*> SessionManager::sessions()
00243 {
00244 return _sessions;
00245 }
00246
00247 void SessionManager::updateSession(Session* session)
00248 {
00249 Profile::Ptr info = _sessionProfiles[session];
00250
00251 Q_ASSERT( info );
00252
00253 applyProfile(session,info,false);
00254
00255
00256
00257 emit sessionUpdated(session);
00258 }
00259
00260 Session* SessionManager::createSession(Profile::Ptr info)
00261 {
00262 Session* session = 0;
00263
00264 if (!info)
00265 info = defaultProfile();
00266
00267 if (!_types.contains(info))
00268 addProfile(info);
00269
00270
00271 session = new Session();
00272 applyProfile(session,info,false);
00273
00274 connect( session , SIGNAL(profileChangeCommandReceived(QString)) , this ,
00275 SLOT(sessionProfileCommandReceived(QString)) );
00276
00277
00278 _sessionMapper->setMapping(session,session);
00279 connect( session , SIGNAL(finished()) , _sessionMapper ,
00280 SLOT(map()) );
00281
00282
00283 _sessions << session;
00284 _sessionProfiles.insert(session,info);
00285
00286 Q_ASSERT( session );
00287
00288 return session;
00289 }
00290
00291 void SessionManager::sessionTerminated(QObject* sessionObject)
00292 {
00293 Session* session = qobject_cast<Session*>(sessionObject);
00294
00295 Q_ASSERT( session );
00296
00297 _sessions.removeAll(session);
00298 session->deleteLater();
00299 }
00300
00301 QList<Profile::Ptr> SessionManager::loadedProfiles() const
00302 {
00303 return _types.toList();
00304 }
00305
00306 Profile::Ptr SessionManager::defaultProfile() const
00307 {
00308 return _defaultProfile;
00309 }
00310 Profile::Ptr SessionManager::fallbackProfile() const
00311 { return _fallbackProfile; }
00312
00313 QString SessionManager::saveProfile(Profile::Ptr info)
00314 {
00315 ProfileWriter* writer = new KDE4ProfileWriter;
00316
00317 QString newPath = writer->getPath(info);
00318
00319 writer->writeProfile(newPath,info);
00320
00321 delete writer;
00322
00323 return newPath;
00324 }
00325
00326 void SessionManager::changeProfile(Profile::Ptr info ,
00327 QHash<Profile::Property,QVariant> propertyMap, bool persistant)
00328 {
00329 Q_ASSERT(info);
00330
00331
00332 QListIterator<Profile::Property> iter(propertyMap.keys());
00333 while ( iter.hasNext() )
00334 {
00335 const Profile::Property property = iter.next();
00336 info->setProperty(property,propertyMap[property]);
00337 }
00338
00339
00340
00341
00342
00343
00344
00345 ProfileGroup::Ptr group = info->asGroup();
00346 if (group)
00347 {
00348 foreach(Profile::Ptr profile, group->profiles())
00349 changeProfile(profile,propertyMap,persistant);
00350 return;
00351 }
00352
00353
00354 applyProfile(info,true);
00355
00356
00357 emit profileChanged(info);
00358
00359
00360
00361 if ( persistant && !info->isHidden() )
00362 {
00363 info->setProperty(Profile::Path,saveProfile(info));
00364 }
00365 }
00366 void SessionManager::applyProfile(Profile::Ptr info , bool modifiedPropertiesOnly)
00367 {
00368 QListIterator<Session*> iter(_sessions);
00369 while ( iter.hasNext() )
00370 {
00371 Session* next = iter.next();
00372 if ( _sessionProfiles[next] == info )
00373 applyProfile(next,info,modifiedPropertiesOnly);
00374 }
00375 }
00376 Profile::Ptr SessionManager::sessionProfile(Session* session) const
00377 {
00378 return _sessionProfiles[session];
00379 }
00380 void SessionManager::setSessionProfile(Session* session, Profile::Ptr profile)
00381 {
00382 _sessionProfiles[session] = profile;
00383 updateSession(session);
00384 }
00385 void SessionManager::applyProfile(Session* session, const Profile::Ptr info , bool modifiedPropertiesOnly)
00386 {
00387 Q_ASSERT(info);
00388
00389 _sessionProfiles[session] = info;
00390
00391 ShouldApplyProperty apply(info,modifiedPropertiesOnly);
00392
00393
00394 if ( apply.shouldApply(Profile::Name) )
00395 session->setTitle(Session::NameRole,info->name());
00396
00397 if ( apply.shouldApply(Profile::Command) )
00398 session->setProgram(info->command());
00399
00400 if ( apply.shouldApply(Profile::Arguments) )
00401 session->setArguments(info->arguments());
00402
00403 if ( apply.shouldApply(Profile::Directory) )
00404 session->setInitialWorkingDirectory(info->defaultWorkingDirectory());
00405
00406 if ( apply.shouldApply(Profile::Environment) )
00407 {
00408
00409
00410 QStringList environment = info->property<QStringList>(Profile::Environment);
00411 environment << QString("PROFILEHOME=%1").arg(info->defaultWorkingDirectory());
00412
00413 session->setEnvironment(environment);
00414 }
00415
00416 if ( apply.shouldApply(Profile::Icon) )
00417 session->setIconName(info->icon());
00418
00419
00420 if ( apply.shouldApply(Profile::KeyBindings) )
00421 session->setKeyBindings(info->property<QString>(Profile::KeyBindings));
00422
00423
00424 if ( apply.shouldApply(Profile::LocalTabTitleFormat) )
00425 session->setTabTitleFormat( Session::LocalTabTitle ,
00426 info->property<QString>(Profile::LocalTabTitleFormat));
00427 if ( apply.shouldApply(Profile::RemoteTabTitleFormat) )
00428 session->setTabTitleFormat( Session::RemoteTabTitle ,
00429 info->property<QString>(Profile::RemoteTabTitleFormat));
00430
00431
00432 if ( apply.shouldApply(Profile::HistoryMode) || apply.shouldApply(Profile::HistorySize) )
00433 {
00434 int mode = info->property<int>(Profile::HistoryMode);
00435 switch ((Profile::HistoryModeEnum)mode)
00436 {
00437 case Profile::DisableHistory:
00438 session->setHistoryType( HistoryTypeNone() );
00439 break;
00440 case Profile::FixedSizeHistory:
00441 {
00442 int lines = info->property<int>(Profile::HistorySize);
00443 session->setHistoryType( HistoryTypeBuffer(lines) );
00444 }
00445 break;
00446 case Profile::UnlimitedHistory:
00447 session->setHistoryType( HistoryTypeFile() );
00448 break;
00449 }
00450 }
00451
00452
00453 if ( apply.shouldApply(Profile::FlowControlEnabled) )
00454 session->setFlowControlEnabled( info->property<bool>(Profile::FlowControlEnabled) );
00455
00456
00457 if ( apply.shouldApply(Profile::DefaultEncoding) )
00458 {
00459 QByteArray name = info->property<QString>(Profile::DefaultEncoding).toUtf8();
00460 session->setCodec( QTextCodec::codecForName(name) );
00461 }
00462 }
00463
00464 void SessionManager::addProfile(Profile::Ptr type)
00465 {
00466 if ( _types.isEmpty() )
00467 _defaultProfile = type;
00468
00469 _types.insert(type);
00470
00471 emit profileAdded(type);
00472 }
00473
00474 bool SessionManager::deleteProfile(Profile::Ptr type)
00475 {
00476 bool wasDefault = ( type == defaultProfile() );
00477
00478 if ( type )
00479 {
00480
00481 if ( type->isPropertySet(Profile::Path) && QFile::exists(type->path()) )
00482 {
00483 if (!QFile::remove(type->path()))
00484 {
00485 kWarning() << "Could not delete profile: " << type->path()
00486 << "The file is most likely in a directory which is read-only.";
00487
00488 return false;
00489 }
00490 }
00491
00492
00493 setFavorite(type,false);
00494 setShortcut(type,QKeySequence());
00495 _types.remove(type);
00496
00497
00498
00499 type->setHidden(true);
00500 }
00501
00502
00503
00504 if ( wasDefault )
00505 {
00506 setDefaultProfile( _types.toList().first() );
00507 }
00508
00509 emit profileRemoved(type);
00510
00511 return true;
00512 }
00513 void SessionManager::setDefaultProfile(Profile::Ptr info)
00514 {
00515 Q_ASSERT ( _types.contains(info) );
00516
00517 _defaultProfile = info;
00518
00519 QString path = info->path();
00520
00521 if ( path.isEmpty() )
00522 path = KDE4ProfileWriter().getPath(info);
00523
00524 QFileInfo fileInfo(path);
00525
00526 KSharedConfigPtr config = KGlobal::config();
00527 KConfigGroup group = config->group("Desktop Entry");
00528 group.writeEntry("DefaultProfile",fileInfo.fileName());
00529 }
00530 QSet<Profile::Ptr> SessionManager::findFavorites()
00531 {
00532 if (!_loadedFavorites)
00533 loadFavorites();
00534
00535 return _favorites;
00536 }
00537 void SessionManager::setFavorite(Profile::Ptr info , bool favorite)
00538 {
00539 if (!_types.contains(info))
00540 addProfile(info);
00541
00542 if ( favorite && !_favorites.contains(info) )
00543 {
00544 _favorites.insert(info);
00545 emit favoriteStatusChanged(info,favorite);
00546 }
00547 else if ( !favorite && _favorites.contains(info) )
00548 {
00549 _favorites.remove(info);
00550 emit favoriteStatusChanged(info,favorite);
00551 }
00552 }
00553 void SessionManager::loadShortcuts()
00554 {
00555 KSharedConfigPtr appConfig = KGlobal::config();
00556 KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
00557
00558 QMap<QString,QString> entries = shortcutGroup.entryMap();
00559
00560 QMapIterator<QString,QString> iter(entries);
00561 while ( iter.hasNext() )
00562 {
00563 iter.next();
00564
00565 QKeySequence shortcut = QKeySequence::fromString(iter.key());
00566 QString profilePath = iter.value();
00567
00568 ShortcutData data;
00569 data.profilePath = profilePath;
00570
00571 _shortcuts.insert(shortcut,data);
00572 }
00573 }
00574 void SessionManager::saveShortcuts()
00575 {
00576 KSharedConfigPtr appConfig = KGlobal::config();
00577 KConfigGroup shortcutGroup = appConfig->group("Profile Shortcuts");
00578 shortcutGroup.deleteGroup();
00579
00580 QMapIterator<QKeySequence,ShortcutData> iter(_shortcuts);
00581 while ( iter.hasNext() )
00582 {
00583 iter.next();
00584
00585 QString shortcutString = iter.key().toString();
00586
00587 shortcutGroup.writeEntry(shortcutString,
00588 iter.value().profilePath);
00589 }
00590 }
00591 void SessionManager::setShortcut(Profile::Ptr info ,
00592 const QKeySequence& keySequence )
00593 {
00594 QKeySequence existingShortcut = shortcut(info);
00595 _shortcuts.remove(existingShortcut);
00596
00597 if (keySequence.isEmpty())
00598 return;
00599
00600 ShortcutData data;
00601 data.profileKey = info;
00602 data.profilePath = info->path();
00603
00604
00605 _shortcuts.insert(keySequence,data);
00606
00607 emit shortcutChanged(info,keySequence);
00608 }
00609 void SessionManager::loadFavorites()
00610 {
00611 KSharedConfigPtr appConfig = KGlobal::config();
00612 KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles");
00613
00614 QSet<QString> favoriteSet;
00615
00616 if ( favoriteGroup.hasKey("Favorites") )
00617 {
00618 QStringList list = favoriteGroup.readEntry("Favorites", QStringList());
00619 favoriteSet = QSet<QString>::fromList(list);
00620 }
00621 else
00622 {
00623
00624
00625 favoriteSet << "Shell.profile";
00626 }
00627
00628
00629 QSetIterator<Profile::Ptr> iter(_types);
00630 while ( iter.hasNext() )
00631 {
00632 Profile::Ptr profile = iter.next();
00633 const QString& path = profile->path();
00634 if ( favoriteSet.contains( path ) )
00635 {
00636 _favorites.insert( profile );
00637 favoriteSet.remove(path);
00638 }
00639 }
00640
00641 QSetIterator<QString> unloadedFavoriteIter(favoriteSet);
00642 while ( unloadedFavoriteIter.hasNext() )
00643 {
00644 Profile::Ptr profile = loadProfile(unloadedFavoriteIter.next());
00645 if (profile)
00646 _favorites.insert(profile);
00647 }
00648
00649 _loadedFavorites = true;
00650 }
00651 void SessionManager::saveFavorites()
00652 {
00653 KSharedConfigPtr appConfig = KGlobal::config();
00654 KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles");
00655
00656 QStringList paths;
00657 QSetIterator<Profile::Ptr> keyIter(_favorites);
00658 while ( keyIter.hasNext() )
00659 {
00660 Profile::Ptr profile = keyIter.next();
00661
00662 Q_ASSERT( _types.contains(profile) && profile );
00663
00664 paths << profile->path();
00665 }
00666
00667 favoriteGroup.writeEntry("Favorites",paths);
00668 }
00669
00670 QList<QKeySequence> SessionManager::shortcuts()
00671 {
00672 return _shortcuts.keys();
00673 }
00674
00675 Profile::Ptr SessionManager::findByShortcut(const QKeySequence& shortcut)
00676 {
00677 Q_ASSERT( _shortcuts.contains(shortcut) );
00678
00679 if ( !_shortcuts[shortcut].profileKey )
00680 {
00681 Profile::Ptr key = loadProfile(_shortcuts[shortcut].profilePath);
00682 if (!key)
00683 {
00684 _shortcuts.remove(shortcut);
00685 return Profile::Ptr();
00686 }
00687 _shortcuts[shortcut].profileKey = key;
00688 }
00689
00690 return _shortcuts[shortcut].profileKey;
00691 }
00692
00693 void SessionManager::sessionProfileCommandReceived(const QString& text)
00694 {
00695
00696
00697
00698
00699 Session* session = qobject_cast<Session*>(sender());
00700 Q_ASSERT( session );
00701
00702 ProfileCommandParser parser;
00703 QHash<Profile::Property,QVariant> changes = parser.parse(text);
00704
00705 Profile::Ptr newProfile = Profile::Ptr(new Profile(_sessionProfiles[session]));
00706
00707 QHashIterator<Profile::Property,QVariant> iter(changes);
00708 while ( iter.hasNext() )
00709 {
00710 iter.next();
00711 newProfile->setProperty(iter.key(),iter.value());
00712 }
00713
00714 _sessionProfiles[session] = newProfile;
00715 applyProfile(newProfile,true);
00716 emit sessionUpdated(session);
00717 }
00718
00719 QKeySequence SessionManager::shortcut(Profile::Ptr info) const
00720 {
00721 QMapIterator<QKeySequence,ShortcutData> iter(_shortcuts);
00722 while (iter.hasNext())
00723 {
00724 iter.next();
00725 if ( iter.value().profileKey == info
00726 || iter.value().profilePath == info->path() )
00727 return iter.key();
00728 }
00729
00730 return QKeySequence();
00731 }
00732
00733 void SessionManager::saveSessions(KConfig* config)
00734 {
00735
00736
00737 int n = 1;
00738 _restoreMapping.clear();
00739
00740 foreach(Session* session, _sessions)
00741 {
00742 QString name = QLatin1String("Session") + QString::number(n);
00743 KConfigGroup group(config, name);
00744
00745 group.writePathEntry("Profile",
00746 _sessionProfiles.value(session)->path());
00747 session->saveSession(group);
00748 _restoreMapping.insert(session, n);
00749 n++;
00750 }
00751
00752 KConfigGroup group(config, "Number");
00753 group.writeEntry("NumberOfSessions", _sessions.count());
00754 }
00755
00756 int SessionManager::getRestoreId(Session* session)
00757 {
00758 return _restoreMapping.value(session);
00759 }
00760
00761 void SessionManager::restoreSessions(KConfig* config)
00762 {
00763 KConfigGroup group(config, "Number");
00764 int sessions;
00765
00766
00767 if ((sessions = group.readEntry("NumberOfSessions", 0)) > 0)
00768 {
00769 for (int n = 1; n <= sessions; n++)
00770 {
00771 QString name = QLatin1String("Session") + QString::number(n);
00772 KConfigGroup sessionGroup(config, name);
00773
00774 QString profile = sessionGroup.readPathEntry("Profile", QString());
00775 Profile::Ptr ptr = defaultProfile();
00776 if (!profile.isEmpty()) ptr = loadProfile(profile);
00777
00778 Session* session = createSession(ptr);
00779 session->restoreSession(sessionGroup);
00780 }
00781 }
00782 }
00783
00784 Session* SessionManager::idToSession(int id)
00785 {
00786 Q_ASSERT(id);
00787 foreach(Session* session, _sessions)
00788 if (session->sessionId() == id)
00789 return session;
00790
00791
00792 Q_ASSERT(0);
00793 return 0;
00794 }
00795
00796 K_GLOBAL_STATIC( SessionManager , theSessionManager )
00797 SessionManager* SessionManager::instance()
00798 {
00799 return theSessionManager;
00800 }
00801
00802 SessionListModel::SessionListModel(QObject* parent)
00803 : QAbstractListModel(parent)
00804 {
00805 }
00806
00807 void SessionListModel::setSessions(const QList<Session*>& sessions)
00808 {
00809 _sessions = sessions;
00810
00811 foreach(Session* session, sessions)
00812 connect(session,SIGNAL(finished()),this,SLOT(sessionFinished()));
00813
00814 reset();
00815 }
00816 QVariant SessionListModel::data(const QModelIndex& index, int role) const
00817 {
00818 Q_ASSERT(index.isValid());
00819
00820 int row = index.row();
00821 int column = index.column();
00822
00823 Q_ASSERT( row >= 0 && row < _sessions.count() );
00824 Q_ASSERT( column >= 0 && column < 2 );
00825
00826 switch (role)
00827 {
00828 case Qt::DisplayRole:
00829 if (column == 1)
00830 return _sessions[row]->title(Session::DisplayedTitleRole);
00831 else if (column == 0)
00832 return _sessions[row]->sessionId();
00833 break;
00834 case Qt::DecorationRole:
00835 if (column == 1)
00836 return KIcon(_sessions[row]->iconName());
00837 else
00838 return QVariant();
00839 }
00840
00841 return QVariant();
00842 }
00843 QVariant SessionListModel::headerData(int section, Qt::Orientation orientation,
00844 int role) const
00845 {
00846 if (role != Qt::DisplayRole)
00847 return QVariant();
00848
00849 if (orientation == Qt::Vertical)
00850 return QVariant();
00851 else
00852 {
00853 switch (section)
00854 {
00855 case 0:
00856 return i18n("Number");
00857 case 1:
00858 return i18n("Title");
00859 default:
00860 return QVariant();
00861 }
00862 }
00863 }
00864
00865 int SessionListModel::columnCount(const QModelIndex&) const
00866 {
00867 return 2;
00868 }
00869 int SessionListModel::rowCount(const QModelIndex&) const
00870 {
00871 return _sessions.count();
00872 }
00873 QModelIndex SessionListModel::parent(const QModelIndex&) const
00874 {
00875 return QModelIndex();
00876 }
00877 void SessionListModel::sessionFinished()
00878 {
00879 Session* session = qobject_cast<Session*>(sender());
00880 int row = _sessions.indexOf(session);
00881
00882 if (row != -1)
00883 {
00884 beginRemoveRows(QModelIndex(),row,row);
00885 sessionRemoved(session);
00886 _sessions.removeAt(row);
00887 endRemoveRows();
00888 }
00889 }
00890 QModelIndex SessionListModel::index(int row, int column, const QModelIndex& parent) const
00891 {
00892 if (hasIndex(row,column,parent))
00893 return createIndex(row,column,_sessions[row]);
00894 else
00895 return QModelIndex();
00896 }
00897
00898 #include "SessionManager.moc"
00899
00900
00901
00902
00903
00904
00905
00906
00907