00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "MainWindow.h"
00022
00023
00024 #include <QtGui/QBoxLayout>
00025
00026
00027 #include <KAction>
00028 #include <KActionCollection>
00029 #include <KActionMenu>
00030 #include <KApplication>
00031 #include <KShortcutsDialog>
00032 #include <KLocale>
00033 #include <KMenu>
00034 #include <KMenuBar>
00035 #include <KMessageBox>
00036 #include <KService>
00037 #include <KToggleAction>
00038 #include <KToggleFullScreenAction>
00039 #include <KToolInvocation>
00040 #include <KStandardAction>
00041 #include <KStandardGuiItem>
00042 #include <KXMLGUIFactory>
00043 #include <KNotifyConfigWidget>
00044
00045
00046 #include "BookmarkHandler.h"
00047 #include "IncrementalSearchBar.h"
00048 #include "RemoteConnectionDialog.h"
00049 #include "SessionController.h"
00050 #include "ProfileList.h"
00051 #include "ManageProfilesDialog.h"
00052 #include "Session.h"
00053 #include "ViewManager.h"
00054 #include "ViewSplitter.h"
00055
00056 using namespace Konsole;
00057
00058 MainWindow::MainWindow()
00059 : KXmlGuiWindow() ,
00060 _bookmarkHandler(0),
00061 _pluggedController(0),
00062 _menuBarVisibilitySet(false)
00063 {
00064
00065
00066
00067 setXMLFile("konsole/konsoleui.rc");
00068
00069 setupActions();
00070
00071
00072 _viewManager = new ViewManager(this,actionCollection());
00073 connect( _viewManager , SIGNAL(empty()) , this , SLOT(close()) );
00074 connect( _viewManager , SIGNAL(activeViewChanged(SessionController*)) , this ,
00075 SLOT(activeViewChanged(SessionController*)) );
00076 connect( _viewManager , SIGNAL(viewPropertiesChanged(const QList<ViewProperties*>&)) ,
00077 bookmarkHandler() , SLOT(setViews(const QList<ViewProperties*>&)) );
00078
00079 connect( _viewManager , SIGNAL(setMenuBarVisibleRequest(bool)) , this ,
00080 SLOT(setMenuBarVisibleOnce(bool)) );
00081 connect( _viewManager , SIGNAL(newViewRequest()) , this , SLOT(newTab()) );
00082
00083
00084 setupWidgets();
00085
00086
00087 createGUI();
00088
00089
00090
00091 correctShortcuts();
00092
00093
00094 setAutoSaveSettings("MainWindow",true);
00095 }
00096
00097 void MainWindow::setMenuBarVisibleOnce(bool visible)
00098 {
00099 if (_menuBarVisibilitySet || menuBar()->isTopLevelMenu() )
00100 return;
00101
00102 menuBar()->setVisible(visible);
00103 _toggleMenuBarAction->setChecked(visible);
00104
00105 _menuBarVisibilitySet = true;
00106 }
00107
00108 void MainWindow::correctShortcuts()
00109 {
00110
00111 QAction* helpAction = actionCollection()->action("help_contents");
00112
00113 Q_ASSERT( helpAction );
00114
00115 helpAction->setShortcut( QKeySequence() );
00116 }
00117
00118 void MainWindow::setDefaultProfile(const QString& key)
00119 {
00120 _defaultProfile = key;
00121 }
00122 QString MainWindow::defaultProfile() const
00123 {
00124 return _defaultProfile;
00125 }
00126
00127 ViewManager* MainWindow::viewManager() const
00128 {
00129 return _viewManager;
00130 }
00131
00132 void MainWindow::disconnectController(SessionController* controller)
00133 {
00134 disconnect( controller , SIGNAL(titleChanged(ViewProperties*))
00135 , this , SLOT(activeViewTitleChanged(ViewProperties*)) );
00136
00137
00138
00139
00140
00141 if (controller->isValid())
00142 guiFactory()->removeClient(controller);
00143
00144 controller->setSearchBar(0);
00145 }
00146
00147 void MainWindow::activeViewChanged(SessionController* controller)
00148 {
00149
00150 bookmarkHandler()->setActiveView(controller);
00151 disconnect( bookmarkHandler() , SIGNAL(openUrl(const KUrl&)) , 0 , 0 );
00152 connect( bookmarkHandler() , SIGNAL(openUrl(const KUrl&)) , controller ,
00153 SLOT(openUrl(const KUrl&)) );
00154
00155 if ( _pluggedController )
00156 disconnectController(_pluggedController);
00157
00158
00159 Q_ASSERT( controller );
00160
00161 connect( controller , SIGNAL(titleChanged(ViewProperties*)) ,
00162 this , SLOT(activeViewTitleChanged(ViewProperties*)) );
00163
00164 controller->setShowMenuAction( _toggleMenuBarAction );
00165 guiFactory()->addClient(controller);
00166
00167
00168 controller->setSearchBar( searchBar() );
00169
00170
00171 activeViewTitleChanged(controller);
00172
00173 _pluggedController = controller;
00174 }
00175
00176 void MainWindow::activeViewTitleChanged(ViewProperties* properties)
00177 {
00178 setPlainCaption(properties->title());
00179 }
00180
00181 IncrementalSearchBar* MainWindow::searchBar() const
00182 {
00183 return _searchBar;
00184 }
00185
00186 void MainWindow::setupActions()
00187 {
00188 KActionCollection* collection = actionCollection();
00189
00190
00191 KAction* newTabAction = collection->addAction("new-tab");
00192 newTabAction->setIcon( KIcon("tab-new") );
00193 newTabAction->setText( i18n("New &Tab") );
00194 newTabAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_N) );
00195 connect( newTabAction , SIGNAL(triggered()) , this , SLOT(newTab()) );
00196
00197 KAction* newWindowAction = collection->addAction("new-window");
00198 newWindowAction->setIcon( KIcon("window-new") );
00199 newWindowAction->setText( i18n("New &Window") );
00200 newWindowAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_M) );
00201 connect( newWindowAction , SIGNAL(triggered()) , this , SLOT(newWindow()) );
00202
00203 KAction* remoteConnectionAction = collection->addAction("remote-connection");
00204 remoteConnectionAction->setText( i18n("Remote Connection...") );
00205 remoteConnectionAction->setIcon( KIcon("network-connect") );
00206 remoteConnectionAction->setShortcut( QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_R) );
00207 connect( remoteConnectionAction , SIGNAL(triggered()) , this , SLOT(showRemoteConnectionDialog()) );
00208
00209
00210 #ifndef KONSOLE_PART
00211 KAction* quitAction = KStandardAction::quit( this , SLOT(close()) , collection );
00212
00213
00214 quitAction->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_Q);
00215 #endif
00216
00217
00218 KActionMenu* bookmarkMenu = new KActionMenu(i18n("&Bookmarks") , collection );
00219 _bookmarkHandler = new BookmarkHandler( collection , bookmarkMenu->menu() , true , this );
00220 collection->addAction("bookmark" , bookmarkMenu);
00221
00222 connect( _bookmarkHandler , SIGNAL(openUrls(QList<KUrl>)) , this , SLOT(openUrls(QList<KUrl>)) );
00223
00224
00225
00226
00227
00228 _toggleMenuBarAction = new KToggleAction(this);
00229 _toggleMenuBarAction->setText( i18n("Show Menu Bar") );
00230 _toggleMenuBarAction->setIcon( KIcon("show-menu") );
00231 _toggleMenuBarAction->setChecked( !menuBar()->isHidden() );
00232 connect( _toggleMenuBarAction , SIGNAL(toggled(bool)) , menuBar() , SLOT(setVisible(bool)) );
00233 collection->addAction("show-menubar",_toggleMenuBarAction);
00234
00235
00236 if ( menuBar()->isTopLevelMenu() )
00237 _toggleMenuBarAction->setVisible(false);
00238
00239
00240 KToggleFullScreenAction* fullScreenAction = new KToggleFullScreenAction(this);
00241 fullScreenAction->setWindow(this);
00242 fullScreenAction->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_F11 );
00243 collection->addAction("view-full-screen",fullScreenAction);
00244 connect( fullScreenAction , SIGNAL(toggled(bool)) , this , SLOT(viewFullScreen(bool)) );
00245
00246
00247 KStandardAction::configureNotifications( this , SLOT(configureNotifications()) , collection );
00248 KStandardAction::keyBindings( this , SLOT(showShortcutsDialog()) , collection );
00249
00250 KAction* manageProfilesAction = collection->addAction("manage-profiles");
00251 manageProfilesAction->setText( i18n("Manage Profiles...") );
00252 manageProfilesAction->setIcon( KIcon("configure") );
00253 connect( manageProfilesAction , SIGNAL(triggered()) , this , SLOT(showManageProfilesDialog()) );
00254
00255 }
00256
00257 void MainWindow::viewFullScreen(bool fullScreen)
00258 {
00259 if ( fullScreen )
00260 setWindowState( windowState() | Qt::WindowFullScreen );
00261 else
00262 setWindowState( windowState() & ~Qt::WindowFullScreen );
00263 }
00264
00265 BookmarkHandler* MainWindow::bookmarkHandler() const
00266 {
00267 return _bookmarkHandler;
00268 }
00269
00270 void MainWindow::setSessionList(ProfileList* list)
00271 {
00272 sessionListChanged(list->actions());
00273
00274 connect( list , SIGNAL(profileSelected(const QString&)) , this ,
00275 SLOT(newFromProfile(const QString&)) );
00276
00277 connect( list , SIGNAL(actionsChanged(const QList<QAction*>&)) , this ,
00278 SLOT(sessionListChanged(const QList<QAction*>&)) );
00279 }
00280
00281 void MainWindow::sessionListChanged(const QList<QAction*>& actions)
00282 {
00283 unplugActionList("favorite-profiles");
00284 plugActionList("favorite-profiles",actions);
00285 }
00286
00287 QString MainWindow::activeSessionDir() const
00288 {
00289 if ( _pluggedController )
00290 return _pluggedController->currentDir();
00291 else
00292 return QString();
00293 }
00294
00295 void MainWindow::openUrls(const QList<KUrl>& urls)
00296 {
00297
00298 foreach( const KUrl& url , urls )
00299 {
00300 if ( url.isLocalFile() )
00301 emit newSessionRequest( _defaultProfile , url.path() , _viewManager );
00302 }
00303 }
00304
00305 void MainWindow::newTab()
00306 {
00307 emit newSessionRequest( _defaultProfile , activeSessionDir() , _viewManager);
00308 }
00309
00310 void MainWindow::newWindow()
00311 {
00312 emit newWindowRequest( _defaultProfile , activeSessionDir() );
00313 }
00314
00315 bool MainWindow::queryClose()
00316 {
00317 if (kapp->sessionSaving() ||
00318 _viewManager->viewProperties().count() < 2)
00319 return true;
00320
00321 int result = KMessageBox::warningYesNoCancel(this,
00322 i18n("You have multiple tabs in this window, "
00323 "are you sure you want to quit?"),
00324 i18n("Really Quit?"),
00325 KStandardGuiItem::quit(),
00326 KGuiItem(i18n("Close current tab"), "tab-close"),
00327 KStandardGuiItem::cancel(),
00328 "CloseAllTabs");
00329
00330 switch (result)
00331 {
00332 case KMessageBox::Yes:
00333 return true;
00334 case KMessageBox::No:
00335 if (_pluggedController && _pluggedController->session())
00336 {
00337 disconnectController(_pluggedController);
00338 _pluggedController->session()->close();
00339 }
00340 return false;
00341 case KMessageBox::Cancel:
00342 return false;
00343 }
00344
00345 return true;
00346 }
00347
00348 void MainWindow::showShortcutsDialog()
00349 {
00350 KShortcutsDialog::configure( actionCollection() ,
00351 KShortcutsEditor::LetterShortcutsDisallowed, this );
00352 }
00353
00354 void MainWindow::newFromProfile(const QString& key)
00355 {
00356 emit newSessionRequest(key, activeSessionDir(), _viewManager);
00357 }
00358 void MainWindow::showManageProfilesDialog()
00359 {
00360 ManageProfilesDialog* dialog = new ManageProfilesDialog(this);
00361 dialog->show();
00362 }
00363
00364 void MainWindow::showRemoteConnectionDialog()
00365 {
00366 RemoteConnectionDialog dialog(this);
00367 if ( dialog.exec() == QDialog::Accepted )
00368 emit newSessionRequest(dialog.sessionKey(),QString(),_viewManager);
00369 }
00370
00371 void MainWindow::setupWidgets()
00372 {
00373 QWidget* widget = new QWidget(this);
00374 QVBoxLayout* layout = new QVBoxLayout();
00375
00376 _searchBar = new IncrementalSearchBar( IncrementalSearchBar::AllFeatures , this);
00377 _searchBar->setVisible(false);
00378
00379 layout->addWidget( _viewManager->widget() );
00380 layout->addWidget( _searchBar );
00381 layout->setMargin(0);
00382 layout->setSpacing(0);
00383
00384 widget->setLayout(layout);
00385
00386 setCentralWidget(widget);
00387 }
00388
00389 void MainWindow::configureNotifications()
00390 {
00391 KNotifyConfigWidget::configure( this );
00392 }
00393
00394 #include "MainWindow.moc"