diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /kicker/menuext/kate/katesessionmenu.cpp | |
download | tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kicker/menuext/kate/katesessionmenu.cpp')
-rw-r--r-- | kicker/menuext/kate/katesessionmenu.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/kicker/menuext/kate/katesessionmenu.cpp b/kicker/menuext/kate/katesessionmenu.cpp new file mode 100644 index 000000000..63cee8106 --- /dev/null +++ b/kicker/menuext/kate/katesessionmenu.cpp @@ -0,0 +1,150 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2005, Anders Lund <anders@alweb.dk> + */ + +#include "katesessionmenu.h" +#include "katesessionmenu.moc" + +#include <kapplication.h> +#include <kconfig.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <kinputdialog.h> +#include <klibloader.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <ksimpleconfig.h> +#include <kstandarddirs.h> + +#include <qvalidator.h> + +class Validator : public QValidator { + public: + Validator( QObject *parent ) : QValidator( parent, 0 ) {} + ~Validator() {} + virtual QValidator::State validate( QString &, int & ) const { return QValidator::Acceptable; } +}; + +K_EXPORT_KICKER_MENUEXT(kate, KateSessionMenu) + +KateSessionMenu::KateSessionMenu( QWidget *parent, const char *name, const QStringList& ) + : KPanelMenu( parent, name ), + m_parent( parent ) +{ +} + +KateSessionMenu::~KateSessionMenu() +{ +} + +// update the session list and rebuild the menu +void KateSessionMenu::initialize() +{ + if ( initialized() ) + { + return; + } + + m_sessions.clear(); + + int id = 0; + + // no session - exec 'kate' + insertItem( SmallIconSet("kate"), i18n("Start Kate (no arguments)"), id++ ); + + // new session - prompt for a name and exec 'kate --start NAME' + insertItem( SmallIconSet("new"), i18n("New Kate Session"), id++ ); + + // new anonymous session, 'kate --start ""' + insertItem( SmallIconSet("new"), i18n("New Anonymous Session"), id++ ); + + insertSeparator(); + + QStringList list = KGlobal::dirs()->findAllResources( "data", "kate/sessions/*.katesession", false, true); + for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) + { + KSimpleConfig config( *it, true ); + config.setGroup( "General" ); + m_sessions.append( config.readEntry( "Name" ) ); + } + + m_sessions.sort(); + + for ( QStringList::ConstIterator it1 = m_sessions.begin(); it1 != m_sessions.end(); ++it1 ) + { + insertItem( *it1, id++ ); + } + + // means for updating, to let the user manually update if he/she added new sessions. + insertSeparator(); + insertItem( SmallIconSet("reload"), i18n("Reload Session List"), this, SLOT(reinitialize()) ); +} + +void KateSessionMenu::slotExec( int id ) +{ + if ( id < 0 ) + return; + + QStringList args; + if ( id > 0 ) + args << "--start"; + + // If a new session is requested we try to ask for a name. + if ( id == 1 ) + { + bool ok (false); + QString name = KInputDialog::getText( i18n("Session Name"), + i18n("Please enter a name for the new session"), + QString::null, + &ok, 0, 0, new Validator( m_parent ) ); + if ( ! ok ) + return; + + if ( name.isEmpty() && KMessageBox::questionYesNo( 0, + i18n("An unnamed session will not be saved automatically. " + "Do you want to create such a session?"), + i18n("Create anonymous session?"), + KStdGuiItem::yes(), KStdGuiItem::cancel(), + "kate_session_button_create_anonymous" ) == KMessageBox::No ) + return; + + if ( m_sessions.contains( name ) && + KMessageBox::warningYesNo( 0, + i18n("You allready have a session named %1. Do you want to open that session?").arg( name ), + i18n("Session exists") ) == KMessageBox::No ) + return; + else + // mark the menu as dirty so that it gets rebuild at next display + // to show the new session + setInitialized( false ); + + args << name; + } + + else if ( id == 2 ) + args << ""; + + else if ( id > 2 ) + args << m_sessions[ id-3 ]; + + kapp->kdeinitExec("kate", args); +} + + +// kate: space-indent: on; indent-width 2; replace-tabs on; |