~ubuntu-branches/ubuntu/saucy/konsole/saucy-proposed

« back to all changes in this revision

Viewing changes to src/TabTitleFormatAction.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-06 14:29:24 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120606142924-1rekqv6j25lw2k41
Tags: 4:4.8.80-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3
 
 
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.
8
 
 
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.
13
 
 
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
17
 
    02110-1301  USA.
18
 
*/
19
 
 
20
 
// Own
21
 
#include "TabTitleFormatAction.h"
22
 
 
23
 
// Qt
24
 
#include <QtCore/QList>
25
 
#include <QtGui/QMenu>
26
 
 
27
 
// KDE
28
 
#include <KLocale>
29
 
 
30
 
using namespace Konsole;
31
 
 
32
 
const TabTitleFormatAction::Element TabTitleFormatAction::_localElements[] =
33
 
{
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") }
40
 
};
41
 
const int TabTitleFormatAction::_localElementCount =
42
 
    sizeof(_localElements) / sizeof(TabTitleFormatAction::Element);
43
 
 
44
 
const TabTitleFormatAction::Element TabTitleFormatAction::_remoteElements[] =
45
 
{
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: %#") }
51
 
};
52
 
const int TabTitleFormatAction::_remoteElementCount =
53
 
    sizeof(_remoteElements) / sizeof(TabTitleFormatAction::Element);
54
 
 
55
 
TabTitleFormatAction::TabTitleFormatAction(QObject* parent)
56
 
    : QAction(parent)
57
 
    , _context(Session::LocalTabTitle)
58
 
{
59
 
    setMenu( new QMenu() );
60
 
    connect( menu() , SIGNAL(triggered(QAction*)) , this , SLOT(fireElementSelected(QAction*)) );
61
 
}
62
 
TabTitleFormatAction::~TabTitleFormatAction()
63
 
{
64
 
    menu()->deleteLater();
65
 
}
66
 
void TabTitleFormatAction::fireElementSelected(QAction* action)
67
 
{
68
 
    emit dynamicElementSelected(action->data().value<QString>());
69
 
}
70
 
void TabTitleFormatAction::setContext(Session::TabTitleContext context)
71
 
{
72
 
    _context = context;
73
 
 
74
 
    menu()->clear();
75
 
 
76
 
    QList<QAction*> actions;
77
 
 
78
 
    int count = 0;
79
 
    const Element* array = 0;
80
 
 
81
 
    if ( context == Session::LocalTabTitle )
82
 
    {
83
 
        array = _localElements;
84
 
        count = _localElementCount;
85
 
    }
86
 
    else if ( context == Session::RemoteTabTitle )
87
 
    {
88
 
        array = _remoteElements;
89
 
        count = _remoteElementCount;
90
 
    }
91
 
 
92
 
    for ( int i = 0 ; i < count ; i++ )
93
 
    {
94
 
        QAction* action = new QAction(i18n(array[i].description),this);
95
 
        action->setData(array[i].element);
96
 
        actions << action;
97
 
    }
98
 
 
99
 
    menu()->addActions(actions);
100
 
}
101
 
Session::TabTitleContext TabTitleFormatAction::context() const
102
 
{
103
 
    return _context;
104
 
}
105
 
 
106
 
#include "TabTitleFormatAction.moc"
107