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

filelight

  • sources
  • kde-4.14
  • kdeutils
  • filelight
  • src
  • app
historyAction.cpp
Go to the documentation of this file.
1 /***********************************************************************
2 * Copyright 2003-2004 Max Howell <max.howell@methylblue.com>
3 * Copyright 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License or (at your option) version 3 or any later version
9 * accepted by the membership of KDE e.V. (or its successor approved
10 * by the membership of KDE e.V.), which shall act as a proxy
11 * defined in Section 14 of version 3 of the license.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 
22 #include "historyAction.h"
23 
24 #include <KAction>
25 #include <KActionCollection>
26 #include <KConfig>
27 #include <KConfigGroup>
28 #include <KLocale>
29 #include <KStandardShortcut>
30 
31 inline HistoryAction::HistoryAction(const KIcon &icon, const QString &text, KActionCollection *ac)
32  : KAction(icon, text, ac)
33  , m_text(text)
34 {
35  // .ui files make this false, but we can't rely on UI file as it isn't compiled in :(
36  setEnabled(false);
37 }
38 
39 void HistoryAction::push(const QString &path)
40 {
41  if (path.isEmpty()) return;
42 
43  if (m_list.isEmpty() || (!m_list.isEmpty() && (m_list.last() != path)))
44  m_list.append(path);
45 
46  setHelpText(path);
47  setEnabled(true);
48 }
49 
50 QString HistoryAction::pop()
51 {
52  const QString s = m_list.takeLast();
53  if (!m_list.isEmpty())
54  setHelpText(m_list.last());
55 
56  setEnabled();
57  return s;
58 }
59 
60 
61 
62 HistoryCollection::HistoryCollection(KActionCollection *ac, QObject *parent)
63  : QObject(parent)
64  , m_b(new HistoryAction(KIcon(QLatin1String( "go-previous" )), i18nc("Go to the last path viewed", "Back"), ac))
65  , m_f(new HistoryAction(KIcon(QLatin1String( "go-next" )), i18nc("Go to forward in the history of paths viewed", "Forward"), ac))
66  , m_receiver(0)
67 {
68  ac->addAction(QLatin1String( "go_back" ), m_b);
69  ac->addAction(QLatin1String( "go_forward" ), m_f);
70  connect(m_b, SIGNAL(triggered(bool)), SLOT(pop()));
71  connect(m_f, SIGNAL(triggered(bool)), SLOT(pop()));
72 }
73 
74 void HistoryCollection::push(const KUrl &url) //slot
75 {
76  if (!url.isEmpty())
77  {
78  if (!m_receiver)
79  {
80  m_f->clear();
81  m_receiver = m_b;
82  }
83 
84  m_receiver->push(url.path(KUrl::AddTrailingSlash));
85  }
86  m_receiver = 0;
87 }
88 
89 void HistoryCollection::pop() //slot
90 {
91  KUrl url;
92  const QString path = ((HistoryAction*)sender())->pop(); //FIXME here we remove the constness
93  url.setPath(path);
94 
95  m_receiver = (sender() == m_b) ? m_f : m_b;
96 
97  emit activated(url);
98 }
99 
100 void HistoryCollection::save(KConfigGroup &configgroup)
101 {
102  configgroup.writePathEntry("backHistory", m_b->m_list);
103  configgroup.writePathEntry("forwardHistory", m_f->m_list);
104 }
105 
106 void HistoryCollection::restore(const KConfigGroup &configgroup)
107 {
108  m_b->m_list = configgroup.readPathEntry("backHistory", QStringList());
109  m_f->m_list = configgroup.readPathEntry("forwardHistory", QStringList());
110  //TODO texts are not updated - no matter
111 }
112 
113 #include "historyAction.moc"
QObject::sender
QObject * sender() const
HistoryAction::clear
void clear()
Definition: historyAction.h:43
HistoryCollection::save
void save(KConfigGroup &configgroup)
Definition: historyAction.cpp:100
QList::append
void append(const T &value)
HistoryCollection::activated
void activated(const KUrl &)
QObject
HistoryCollection::HistoryCollection
HistoryCollection(KActionCollection *ac, QObject *parent)
Definition: historyAction.cpp:62
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString
QStringList
Filelight::parent
http QObject * parent
Definition: part.cpp:74
HistoryAction
Definition: historyAction.h:32
QList::takeLast
T takeLast()
QLatin1String
KAction
QList::last
T & last()
HistoryCollection::push
void push(const KUrl &)
Definition: historyAction.cpp:74
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
HistoryAction::setEnabled
virtual void setEnabled(bool b=true)
Definition: historyAction.h:39
HistoryCollection::restore
void restore(const KConfigGroup &configgroup)
Definition: historyAction.cpp:106
historyAction.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

filelight

Skip menu "filelight"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

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