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