• 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
ProfileList.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-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 "ProfileList.h"
22 
23 // Qt
24 #include <QAction>
25 #include <QActionGroup>
26 
27 // KDE
28 #include <KIcon>
29 #include <KLocalizedString>
30 #include <KDebug>
31 
32 // Konsole
33 #include "ProfileManager.h"
34 
35 using Konsole::Profile;
36 using Konsole::ProfileList;
37 
38 ProfileList::ProfileList(bool addShortcuts , QObject* parent)
39  : QObject(parent)
40  , _addShortcuts(addShortcuts)
41  , _emptyListAction(0)
42 {
43  // construct the list of favorite profiles
44  _group = new QActionGroup(this);
45 
46  // Even when there are no favorite profiles, allow user to
47  // create new tabs using the default profile from the menu
48  _emptyListAction = new QAction(i18n("Default profile"), _group);
49 
50  // TODO - Handle re-sorts when user changes profile names
51  ProfileManager* manager = ProfileManager::instance();
52  QList<Profile::Ptr> favoriteProfiles = manager->sortedFavorites();
53 
54  foreach(const Profile::Ptr& profile, favoriteProfiles) {
55  favoriteChanged(profile, true);
56  }
57 
58  connect(_group, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*)));
59 
60  // listen for future changes to the profiles
61  connect(manager, SIGNAL(favoriteStatusChanged(Profile::Ptr,bool)), this,
62  SLOT(favoriteChanged(Profile::Ptr,bool)));
63  connect(manager, SIGNAL(shortcutChanged(Profile::Ptr,QKeySequence)), this,
64  SLOT(shortcutChanged(Profile::Ptr,QKeySequence)));
65  connect(manager, SIGNAL(profileChanged(Profile::Ptr)), this,
66  SLOT(profileChanged(Profile::Ptr)));
67 }
68 void ProfileList::updateEmptyAction()
69 {
70  Q_ASSERT(_group);
71  Q_ASSERT(_emptyListAction);
72 
73  // show this action only when it is the only action in the group
74  const bool showEmptyAction = (_group->actions().count() == 1);
75 
76  if (showEmptyAction != _emptyListAction->isVisible())
77  _emptyListAction->setVisible(showEmptyAction);
78 }
79 QAction* ProfileList::actionForProfile(Profile::Ptr profile) const
80 {
81  foreach(QAction* action, _group->actions()) {
82  if (action->data().value<Profile::Ptr>() == profile)
83  return action;
84  }
85  return 0; // not found
86 }
87 
88 void ProfileList::profileChanged(Profile::Ptr profile)
89 {
90  QAction* action = actionForProfile(profile);
91  if (action)
92  updateAction(action, profile);
93 }
94 
95 void ProfileList::updateAction(QAction* action , Profile::Ptr profile)
96 {
97  Q_ASSERT(action);
98  Q_ASSERT(profile);
99 
100  action->setText(profile->name());
101  action->setIcon(KIcon(profile->icon()));
102 }
103 void ProfileList::shortcutChanged(Profile::Ptr profile, const QKeySequence& sequence)
104 {
105  if (!_addShortcuts)
106  return;
107 
108  QAction* action = actionForProfile(profile);
109 
110  if (action) {
111  action->setShortcut(sequence);
112  }
113 }
114 void ProfileList::syncWidgetActions(QWidget* widget, bool sync)
115 {
116  if (!sync) {
117  _registeredWidgets.remove(widget);
118  return;
119  }
120 
121  _registeredWidgets.insert(widget);
122 
123  const QList<QAction*> currentActions = widget->actions();
124  foreach(QAction * currentAction, currentActions) {
125  widget->removeAction(currentAction);
126  }
127 
128  widget->addActions(_group->actions());
129 }
130 void ProfileList::favoriteChanged(Profile::Ptr profile, bool isFavorite)
131 {
132  ProfileManager* manager = ProfileManager::instance();
133 
134  if (isFavorite) {
135  QAction* action = new QAction(_group);
136  action->setData(QVariant::fromValue(profile));
137 
138  if (_addShortcuts) {
139  action->setShortcut(manager->shortcut(profile));
140  }
141 
142  updateAction(action, profile);
143 
144  foreach(QWidget * widget, _registeredWidgets) {
145  widget->addAction(action);
146  }
147  emit actionsChanged(_group->actions());
148  } else {
149  QAction* action = actionForProfile(profile);
150 
151  if (action) {
152  _group->removeAction(action);
153  foreach(QWidget * widget, _registeredWidgets) {
154  widget->removeAction(action);
155  }
156  emit actionsChanged(_group->actions());
157  }
158  }
159 
160  updateEmptyAction();
161 }
162 void ProfileList::triggered(QAction* action)
163 {
164  emit profileSelected(action->data().value<Profile::Ptr>());
165 }
166 
167 QList<QAction*> ProfileList::actions()
168 {
169  return _group->actions();
170 }
171 
172 #include "ProfileList.moc"
QAction::setText
void setText(const QString &text)
QWidget
Konsole::ProfileList::actions
QList< QAction * > actions()
Returns a list of actions representing profiles.
Definition: ProfileList.cpp:167
QActionGroup
Konsole::ProfileManager
Manages profiles which specify various settings for terminal sessions and their displays.
Definition: ProfileManager.h:48
QWidget::addAction
void addAction(QAction *action)
QWidget::addActions
void addActions(QList< QAction * > actions)
QAction::data
QVariant data() const
QAction::setIcon
void setIcon(const QIcon &icon)
QAction::isVisible
bool isVisible() const
Konsole::ProfileList
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Definition: ProfileList.h:51
QVariant::value
T value() const
Konsole::ProfileList::actionsChanged
void actionsChanged(const QList< QAction * > &actions)
Emitted when the list of actions changes.
QSet::insert
const_iterator insert(const T &value)
Konsole::Profile
Represents a terminal set-up which can be used to set the initial state of new terminal sessions or a...
Definition: Profile.h:60
Konsole::ProfileList::syncWidgetActions
void syncWidgetActions(QWidget *widget, bool sync)
TODO: Document me.
Definition: ProfileList.cpp:114
Konsole::ProfileManager::instance
static ProfileManager * instance()
Returns the profile manager instance.
Definition: ProfileManager.cpp:114
ProfileList.h
QObject
QList
QAction::setData
void setData(const QVariant &userData)
Konsole::ProfileManager::shortcut
QKeySequence shortcut(Profile::Ptr profile) const
Returns the shortcut associated with a particular profile.
Definition: ProfileManager.cpp:622
QAction::setShortcut
void setShortcut(const QKeySequence &shortcut)
QVariant::fromValue
QVariant fromValue(const T &value)
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
QActionGroup::actions
QList< QAction * > actions() const
QSet::remove
bool remove(const T &value)
QKeySequence
ProfileManager.h
Konsole::ProfileManager::sortedFavorites
QList< Profile::Ptr > sortedFavorites()
Definition: ProfileManager.cpp:288
QAction
QWidget::removeAction
void removeAction(QAction *action)
QActionGroup::removeAction
void removeAction(QAction *action)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QWidget::actions
QList< QAction * > actions() const
Konsole::ProfileList::profileSelected
void profileSelected(Profile::Ptr profile)
Emitted when the user selects an action from the list.
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