2
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#include "TabTitleFormatAction.h"
24
#include <QtCore/QList>
25
#include <QtGui/QMenu>
30
using namespace Konsole;
32
const TabTitleFormatAction::Element TabTitleFormatAction::_localElements[] =
34
{ "%n" , I18N_NOOP("Program Name: %n") },
35
{ "%d" , I18N_NOOP("Current Directory (Short): %d") },
36
{ "%D" , I18N_NOOP("Current Directory (Long): %D") },
37
{ "%w" , I18N_NOOP("Window Title Set by Shell: %w") },
38
{ "%#" , I18N_NOOP("Session Number: %#") },
39
{ "%u" , I18N_NOOP("User Name: %u") }
41
const int TabTitleFormatAction::_localElementCount =
42
sizeof(_localElements) / sizeof(TabTitleFormatAction::Element);
44
const TabTitleFormatAction::Element TabTitleFormatAction::_remoteElements[] =
46
{ "%u" , I18N_NOOP("User Name: %u") },
47
{ "%h" , I18N_NOOP("Remote Host (Short): %h") },
48
{ "%H" , I18N_NOOP("Remote Host (Long): %H") },
49
{ "%w" , I18N_NOOP("Window Title Set by Shell: %w") },
50
{ "%#" , I18N_NOOP("Session Number: %#") }
52
const int TabTitleFormatAction::_remoteElementCount =
53
sizeof(_remoteElements) / sizeof(TabTitleFormatAction::Element);
55
TabTitleFormatAction::TabTitleFormatAction(QObject* parent)
57
, _context(Session::LocalTabTitle)
59
setMenu( new QMenu() );
60
connect( menu() , SIGNAL(triggered(QAction*)) , this , SLOT(fireElementSelected(QAction*)) );
62
TabTitleFormatAction::~TabTitleFormatAction()
64
menu()->deleteLater();
66
void TabTitleFormatAction::fireElementSelected(QAction* action)
68
emit dynamicElementSelected(action->data().value<QString>());
70
void TabTitleFormatAction::setContext(Session::TabTitleContext context)
76
QList<QAction*> actions;
79
const Element* array = 0;
81
if ( context == Session::LocalTabTitle )
83
array = _localElements;
84
count = _localElementCount;
86
else if ( context == Session::RemoteTabTitle )
88
array = _remoteElements;
89
count = _remoteElementCount;
92
for ( int i = 0 ; i < count ; i++ )
94
QAction* action = new QAction(i18n(array[i].description),this);
95
action->setData(array[i].element);
99
menu()->addActions(actions);
101
Session::TabTitleContext TabTitleFormatAction::context() const
106
#include "TabTitleFormatAction.moc"