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

akregator

  • sources
  • kde-4.14
  • kdepim
  • akregator
  • src
mainwindow.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "mainwindow.h"
26 #include "akregator_part.h"
27 #include "akregatorconfig.h"
28 #include "trayicon.h"
29 
30 #include "libkdepim/misc/broadcaststatus.h"
31 #include "libkdepim/progresswidget/progressstatusbarwidget.h"
32 #include "libkdepim/progresswidget/statusbarprogresswidget.h"
33 
34 #include <KAction>
35 #include <KActionCollection>
36 #include <KApplication>
37 #include <KConfig>
38 #include <KEditToolBar>
39 #include <KLocalizedString>
40 #include <KMessageBox>
41 #include <KSqueezedTextLabel>
42 #include <KShortcutsDialog>
43 #include <KStandardAction>
44 #include <KStatusBar>
45 #include <KPluginLoader>
46 #include <KMenuBar>
47 #include <KXMLGUIFactory>
48 #include <KToolBar>
49 #include <KPluginFactory>
50 
51 using namespace Akregator;
52 
53 BrowserInterface::BrowserInterface( MainWindow *shell, const char *name )
54  : KParts::BrowserInterface( shell )
55 {
56  setObjectName(QLatin1String(name));
57  m_shell = shell;
58 }
59 
60 MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f )
61  : KParts::MainWindow( parent, f )
62  , m_browserIface( new BrowserInterface( this, "browser_interface" ) )
63  , m_part()
64  , m_statusLabel( new KSqueezedTextLabel( this ) )
65 {
66  setPluginLoadingMode( DoNotLoadPlugins );
67 
68  // set the shell's ui resource file
69  setXMLFile(QLatin1String("akregator_shell.rc"));
70 
71  KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); // options_configure_keybinding
72  KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); // options_configure_toolbars
73 
74  toolBar()->show();
75  statusBar()->show();
76 
77  int statH=fontMetrics().height()+2;
78  m_statusLabel->setTextFormat(Qt::RichText);
79  m_statusLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
80  m_statusLabel->setMinimumWidth( 0 );
81  m_statusLabel->setFixedHeight( statH );
82  statusBar()->addWidget( m_statusLabel, 1 );
83 
84  KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
85  KStandardAction::showMenubar( menuBar(), SLOT(setVisible(bool)), actionCollection());
86  setStandardToolBarMenuEnabled(true);
87  createStandardStatusBarAction();
88 
89  connect( KPIM::BroadcastStatus::instance(), SIGNAL(statusMsg(QString)),
90  this, SLOT(slotSetStatusBarText(QString)) );
91 
92  connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotOnShutdown()));
93 }
94 
95 bool MainWindow::loadPart()
96 {
97  if ( m_part )
98  return true;
99  // this routine will find and load our Part. it finds the Part by
100  // name which is a bad idea usually.. but it's alright in this
101  // case since our Part is made for this Shell
102  KPluginLoader loader(QLatin1String("akregatorpart"));
103  KPluginFactory* const factory = loader.factory();
104  if (!factory) {
105  KMessageBox::error(this, i18n("Could not find the Akregator part; please check your installation.\n%1", loader.errorString()) );
106  return false;
107  }
108 
109  m_part = static_cast<Akregator::Part*>( factory->create<KParts::ReadOnlyPart>(this) );
110 
111  if ( !m_part )
112  return false;
113 
114  m_part->setObjectName(QLatin1String("akregator_part"));
115  setCentralWidget(m_part->widget());
116 
117  connect(m_part, SIGNAL(setWindowCaption(QString)), this, SLOT(setCaption(QString)) );
118 
119  createGUI(m_part);
120  browserExtension(m_part)->setBrowserInterface(m_browserIface);
121  setAutoSaveSettings();
122  return true;
123 }
124 
125 void MainWindow::setupProgressWidgets()
126 {
127  KPIM::ProgressStatusBarWidget * progressStatusBarWidget = new KPIM::ProgressStatusBarWidget(statusBar(), this);
128  statusBar()->addPermanentWidget( progressStatusBarWidget->littleProgress(), 0 );
129 }
130 
131 MainWindow::~MainWindow()
132 {
133 }
134 
135 void MainWindow::saveProperties(KConfigGroup &config)
136 {
137  if (!m_part)
138  loadPart();
139 
140  m_part->saveProperties(config);
141  config.writeEntry("docked", isHidden());
142 }
143 
144 void MainWindow::readProperties(const KConfigGroup & config)
145 {
146  if (!m_part)
147  loadPart();
148  m_part->readProperties(config);
149  setVisible( !Settings::showTrayIcon() || !config.readEntry("docked", false) );
150 }
151 
152 // TODO: move to part?
153 void MainWindow::optionsConfigureKeys()
154 {
155  KShortcutsDialog dlg( KShortcutsEditor::AllActions,
156  KShortcutsEditor::LetterShortcutsAllowed, this );
157 
158  dlg.addCollection(actionCollection());
159  if (m_part)
160  dlg.addCollection(m_part->actionCollection());
161 
162  dlg.configure();
163 }
164 
165 // TODO: move to part?
166 void MainWindow::optionsConfigureToolbars()
167 {
168  saveMainWindowSettings(KGlobal::config().data()->group( autoSaveGroup()) );
169  KEditToolBar dlg(factory());
170  connect(&dlg, SIGNAL(newToolBarConfig()),
171  this, SLOT(applyNewToolbarConfig()));
172  dlg.exec();
173 }
174 
175 // TODO: move to part?
176 void MainWindow::applyNewToolbarConfig()
177 {
178  applyMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) );
179 }
180 
181 KParts::BrowserExtension *MainWindow::browserExtension(KParts::ReadOnlyPart *p)
182 {
183  return KParts::BrowserExtension::childObject( p );
184 }
185 
186 void MainWindow::slotQuit()
187 {
188  kapp->quit();
189 }
190 
191 void MainWindow::slotOnShutdown()
192 {
193  delete m_part;
194 }
195 
196 bool MainWindow::queryClose()
197 {
198  if ( kapp->sessionSaving() ) {
199  return true;
200  }
201  if ( !TrayIcon::getInstance() ) {
202  delete m_part; // delete that here instead of dtor to ensure nested khtmlparts are deleted before singleton objects like KHTMLPageCache
203  return true;
204  }
205 
206  hide();
207  return false;
208 }
209 
210 void MainWindow::slotClearStatusText()
211 {
212  m_statusLabel->setText(QString());
213 }
214 
215 void MainWindow::slotSetStatusBarText( const QString & text )
216 {
217  m_statusLabel->setText(text);
218 }
219 
Akregator::MainWindow::setupProgressWidgets
void setupProgressWidgets()
Creates the progress widget in the status bar and the ProgressDialog and connects them...
Definition: mainwindow.cpp:125
Akregator::MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:131
QWidget
QSizePolicy
Akregator::Part
This is a RSS Aggregator "Part".
Definition: akregator_part.h:77
Akregator::MainWindow::readProperties
void readProperties(const KConfigGroup &)
This method is called when this app is restored.
Definition: mainwindow.cpp:144
Akregator::MainWindow::slotSetStatusBarText
void slotSetStatusBarText(const QString &c)
Definition: mainwindow.cpp:215
Akregator::MainWindow::queryClose
bool queryClose()
Reimplemented to say if app will be running in system tray if necessary.
Definition: mainwindow.cpp:196
Akregator::MainWindow::slotClearStatusText
void slotClearStatusText()
Definition: mainwindow.cpp:210
Akregator::BrowserInterface
Definition: mainwindow.h:44
akregator_part.h
mainwindow.h
QString
trayicon.h
Akregator::MainWindow::loadPart
bool loadPart()
Loads the part.
Definition: mainwindow.cpp:95
Akregator::TrayIcon::getInstance
static TrayIcon * getInstance()
Definition: trayicon.cpp:45
Akregator::MainWindow
This is the application "Shell".
Definition: mainwindow.h:62
Akregator::MainWindow::saveProperties
void saveProperties(KConfigGroup &)
This method is called when it is time for the app to save its properties for session management purpo...
Definition: mainwindow.cpp:135
QLatin1String
Akregator::BrowserInterface::BrowserInterface
BrowserInterface(Akregator::MainWindow *shell, const char *name)
Definition: mainwindow.cpp:53
Akregator::MainWindow::slotQuit
void slotQuit()
Definition: mainwindow.cpp:186
Qt::WindowFlags
typedef WindowFlags
Akregator::MainWindow::MainWindow
MainWindow(QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS)
Definition: mainwindow.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

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