• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
TabTitleFormatButton.cpp
Go to the documentation of this file.
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 "TabTitleFormatButton.h"
22 
23 // Qt
24 #include <QtCore/QList>
25 #include <QMenu>
26 
27 // KDE
28 #include <KLocalizedString>
29 
30 using namespace Konsole;
31 
32 const TabTitleFormatButton::Element TabTitleFormatButton::_localElements[] = {
33  { "%n" , I18N_NOOP("Program Name: %n") },
34  { "%d" , I18N_NOOP("Current Directory (Short): %d") },
35  { "%D" , I18N_NOOP("Current Directory (Long): %D") },
36  { "%w" , I18N_NOOP("Window Title Set by Shell: %w") },
37  { "%#" , I18N_NOOP("Session Number: %#") },
38  { "%u" , I18N_NOOP("User Name: %u") },
39  { "%h" , I18N_NOOP("Local Host: %h") }
40 };
41 const int TabTitleFormatButton::_localElementCount =
42  sizeof(_localElements) / sizeof(TabTitleFormatButton::Element);
43 
44 const TabTitleFormatButton::Element TabTitleFormatButton::_remoteElements[] = {
45  { "%u" , I18N_NOOP("User Name: %u") },
46  { "%h" , I18N_NOOP("Remote Host (Short): %h") },
47  { "%H" , I18N_NOOP("Remote Host (Long): %H") },
48  { "%w" , I18N_NOOP("Window Title Set by Shell: %w") },
49  { "%#" , I18N_NOOP("Session Number: %#") }
50 };
51 const int TabTitleFormatButton::_remoteElementCount =
52  sizeof(_remoteElements) / sizeof(TabTitleFormatButton::Element);
53 
54 TabTitleFormatButton::TabTitleFormatButton(QWidget* aParent)
55  : QPushButton(aParent)
56  , _context(Session::LocalTabTitle)
57 {
58  setText(i18n("Insert"));
59  setMenu(new QMenu());
60  connect(menu() , SIGNAL(triggered(QAction*)) , this , SLOT(fireElementSelected(QAction*)));
61 }
62 
63 TabTitleFormatButton::~TabTitleFormatButton()
64 {
65  menu()->deleteLater();
66 }
67 
68 void TabTitleFormatButton::fireElementSelected(QAction* action)
69 {
70  emit dynamicElementSelected(action->data().value<QString>());
71 }
72 
73 void TabTitleFormatButton::setContext(Session::TabTitleContext titleContext)
74 {
75  _context = titleContext;
76 
77  menu()->clear();
78 
79  int count = 0;
80  const Element* array = 0;
81 
82  if (titleContext == Session::LocalTabTitle) {
83  setToolTip(i18nc("@info:tooltip", "Insert title format"));
84  array = _localElements;
85  count = _localElementCount;
86  } else if (titleContext == Session::RemoteTabTitle) {
87  setToolTip(i18nc("@info:tooltip", "Insert remote title format"));
88  array = _remoteElements;
89  count = _remoteElementCount;
90  }
91 
92  QList<QAction*> menuActions;
93  for (int i = 0 ; i < count ; i++) {
94  QAction* action = new QAction(i18n(array[i].description), this);
95  action->setData(array[i].element);
96  menuActions << action;
97  }
98 
99  menu()->addActions(menuActions);
100 }
101 
102 Session::TabTitleContext TabTitleFormatButton::context() const
103 {
104  return _context;
105 }
106 
107 #include "TabTitleFormatButton.moc"
108 
QPushButton::setMenu
void setMenu(QMenu *menu)
QWidget
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:78
QWidget::addActions
void addActions(QList< QAction * > actions)
QAction::data
QVariant data() const
QVariant::value
T value() const
Konsole::TabTitleFormatButton::context
Session::TabTitleContext context() const
Definition: TabTitleFormatButton.cpp:102
QMenu::clear
void clear()
Konsole::TabTitleFormatButton::~TabTitleFormatButton
~TabTitleFormatButton()
Definition: TabTitleFormatButton.cpp:63
Konsole::TabTitleFormatButton::setContext
void setContext(Session::TabTitleContext context)
Definition: TabTitleFormatButton.cpp:73
Konsole::Session::RemoteTabTitle
Tab title format used session currently contains a connection to a remote computer (via SSH) ...
Definition: Session.h:166
QObject::deleteLater
void deleteLater()
QString
QList
QAction::setData
void setData(const QVariant &userData)
QMenu
TabTitleFormatButton.h
Konsole::TabTitleFormatButton::dynamicElementSelected
void dynamicElementSelected(const QString &)
Konsole::Session::LocalTabTitle
Default tab title format.
Definition: Session.h:161
Konsole::TabTitleFormatButton::TabTitleFormatButton
TabTitleFormatButton(QWidget *parent)
Definition: TabTitleFormatButton.cpp:54
QAction
QAbstractButton::setText
void setText(const QString &text)
QPushButton::menu
QMenu * menu() const
QPushButton
QWidget::setToolTip
void setToolTip(const QString &)
Konsole::Session::TabTitleContext
TabTitleContext
This enum describes the contexts for which separate tab title formats may be specified.
Definition: Session.h:159
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal