From ba84ff30fad87446ada5cdf1ce59e4331e93eed5 Mon Sep 17 00:00:00 2001 From: Jekyll Wu Date: Sun, 29 Jan 2012 07:18:22 +0800 Subject: [PATCH] Get rid of _defaultProfile from class MainWindow REVIEW:103819 --- src/Application.cpp | 50 +++++++++++++++------------------------------ src/Application.h | 4 ++-- src/MainWindow.cpp | 25 +++++------------------ src/MainWindow.h | 16 --------------- 4 files changed, 24 insertions(+), 71 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 646cd4b48..c270caece 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -128,15 +128,15 @@ int Application::newInstance() MainWindow* window = processWindowArgs(args); // select profile to use - processProfileSelectArgs(args, window); + Profile::Ptr baseProfile = processProfileSelectArgs(args); // process various command-line options which cause a property of the // default profile to be changed - processProfileChangeArgs(args, window); + Profile::Ptr newProfile = processProfileChangeArgs(args, baseProfile); if (!args->isSet("tabs-from-file")) { // create new session - Session* session = createSession(window->defaultProfile(), + Session* session = createSession(newProfile, QString(), window->viewManager()); if (!args->isSet("close")) { @@ -257,10 +257,7 @@ void Application::createTabFromArgs(KCmdLineArgs* args, MainWindow* window, // FIXME: A lot of duplicate code below // Get the default profile - Profile::Ptr defaultProfile = window->defaultProfile(); - if (!defaultProfile) { - defaultProfile = SessionManager::instance()->defaultProfile(); - } + Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile(); // Create profile setting, with command and workdir Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile)); @@ -270,13 +267,10 @@ void Application::createTabFromArgs(KCmdLineArgs* args, MainWindow* window, if (args->isSet("workdir")) { newProfile->setProperty(Profile::Directory, args->getOption("workdir")); } - if (!newProfile->isEmpty()) { - window->setDefaultProfile(newProfile); - } // Create the new session - Session* session = createSession(window->defaultProfile(), QString(), - window->viewManager()); + Session* session = createSession(newProfile, QString(), window->viewManager()); + session->setTabTitleFormat(Session::LocalTabTitle, title); session->setTabTitleFormat(Session::RemoteTabTitle, title); // Ensure that new title is displayed @@ -288,11 +282,6 @@ void Application::createTabFromArgs(KCmdLineArgs* args, MainWindow* window, window->resize(window->sizeHint()); } - // Reset the profile to default. Otherwise, the next manually - // created tab would have the command above! - newProfile = Profile::Ptr(new Profile(defaultProfile)); - newProfile->setHidden(true); - window->setDefaultProfile(newProfile); } MainWindow* Application::processWindowArgs(KCmdLineArgs* args) @@ -314,17 +303,18 @@ MainWindow* Application::processWindowArgs(KCmdLineArgs* args) return window; } -void Application::processProfileSelectArgs(KCmdLineArgs* args, - MainWindow* window) +Profile::Ptr Application::processProfileSelectArgs(KCmdLineArgs* args) { + Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile(); + if (args->isSet("profile")) { Profile::Ptr profile = SessionManager::instance()->loadProfile( args->getOption("profile")); - if (!profile) - profile = SessionManager::instance()->defaultProfile(); - - window->setDefaultProfile(profile); + if (profile) + return profile; } + + return defaultProfile; } bool Application::processHelpArgs(KCmdLineArgs* args) @@ -338,13 +328,10 @@ bool Application::processHelpArgs(KCmdLineArgs* args) } return false; } -void Application::processProfileChangeArgs(KCmdLineArgs* args, - MainWindow* window) + +Profile::Ptr Application::processProfileChangeArgs(KCmdLineArgs* args, Profile::Ptr baseProfile) { - Profile::Ptr defaultProfile = window->defaultProfile(); - if (!defaultProfile) - defaultProfile = SessionManager::instance()->defaultProfile(); - Profile::Ptr newProfile = Profile::Ptr(new Profile(defaultProfile)); + Profile::Ptr newProfile = Profile::Ptr(new Profile(baseProfile)); newProfile->setHidden(true); // change the initial working directory @@ -363,9 +350,7 @@ void Application::processProfileChangeArgs(KCmdLineArgs* args, } } - if (!newProfile->isEmpty()) { - window->setDefaultProfile(newProfile); - } + return newProfile; } void Application::startBackgroundMode(MainWindow* window) @@ -416,7 +401,6 @@ void Application::detachView(Session* session) void Application::createWindow(Profile::Ptr profile, const QString& directory) { MainWindow* window = newMainWindow(); - window->setDefaultProfile(profile); createSession(profile, directory, window->viewManager()); window->show(); } diff --git a/src/Application.h b/src/Application.h index 7415fd506..7e02a8eef 100644 --- a/src/Application.h +++ b/src/Application.h @@ -85,8 +85,8 @@ private: void startBackgroundMode(MainWindow* window); bool processHelpArgs(KCmdLineArgs* args); MainWindow* processWindowArgs(KCmdLineArgs* args); - void processProfileSelectArgs(KCmdLineArgs* args, MainWindow* window); - void processProfileChangeArgs(KCmdLineArgs* args, MainWindow* window); + Profile::Ptr processProfileSelectArgs(KCmdLineArgs* args); + Profile::Ptr processProfileChangeArgs(KCmdLineArgs* args, Profile::Ptr baseProfile); void processTabsFromFileArgs(KCmdLineArgs* args, MainWindow* window); void createTabFromArgs(KCmdLineArgs* args, MainWindow* window, const QHash&); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7908394b4..ab8bba6d6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -179,15 +179,6 @@ void MainWindow::correctShortcuts() bookmarkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); } -void MainWindow::setDefaultProfile(Profile::Ptr profile) -{ - _defaultProfile = profile; -} -Profile::Ptr MainWindow::defaultProfile() const -{ - return _defaultProfile; -} - ViewManager* MainWindow::viewManager() const { return _viewManager; @@ -347,7 +338,7 @@ void MainWindow::sessionListChanged(const QList& actions) foreach(QAction * action, actions) { newTabMenu->addAction(action); - // NOTE: _defaultProfile seems to not work here, sigh. + // NOTE: defaultProfile seems to not work here, sigh. Profile::Ptr profile = SessionManager::instance()->defaultProfile(); if (profile && profile->name() == action->text().remove('&')) { action->setIcon(KIcon(profile->icon(), NULL, QStringList("emblem-favorite"))); @@ -387,12 +378,14 @@ QString MainWindow::activeSessionDir() const void MainWindow::openUrls(const QList& urls) { + Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile(); + foreach(const KUrl & url , urls) { if (url.isLocalFile()) - emit newSessionRequest(_defaultProfile , url.path() , _viewManager); + emit newSessionRequest(defaultProfile , url.path() , _viewManager); else if (url.protocol() == "ssh") - emit newSSHSessionRequest(_defaultProfile , url , _viewManager); + emit newSSHSessionRequest(defaultProfile , url , _viewManager); } } @@ -443,19 +436,11 @@ bool MainWindow::queryClose() void MainWindow::saveProperties(KConfigGroup& group) { - if (_defaultProfile) - group.writePathEntry("Default Profile", _defaultProfile->path()); _viewManager->saveSessions(group); } void MainWindow::readProperties(const KConfigGroup& group) { - SessionManager* manager = SessionManager::instance(); - QString profilePath = group.readPathEntry("Default Profile", QString()); - Profile::Ptr profile = manager->defaultProfile(); - if (!profilePath.isEmpty()) - profile = manager->loadProfile(profilePath); - setDefaultProfile(profile); _viewManager->restoreSessions(group); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 2fb1803a1..b3dd2189b 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -87,20 +87,6 @@ public: */ BookmarkHandler* bookmarkHandler() const; - /** - * Sets the default profile for this window. - * This is the default value for the profile argument - * when the newSessionRequest() and newWindow() signals - * are emitted. - */ - void setDefaultProfile(Profile::Ptr profile); - - /** - * Returns the default profile for this window. - * See setDefaultProfile() - */ - Profile::Ptr defaultProfile() const; - signals: /** * Emitted by the main window to request the creation of a new session. @@ -202,8 +188,6 @@ private: QPointer _pluggedController; - Profile::Ptr _defaultProfile; - bool _menuBarInitialVisibilityApplied; };