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

akregator

  • sources
  • kde-4.12
  • 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/progressdialog.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 <KLibLoader>
40 #include <KLocalizedString>
41 #include <KMessageBox>
42 #include <KMenuBar>
43 #include <KSqueezedTextLabel>
44 #include <KStatusBar>
45 #include <KShortcutsDialog>
46 #include <KStandardAction>
47 #include <KToolBar>
48 #include <KStandardDirs>
49 #include <KTemporaryFile>
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_progressBar( 0 )
65  , m_statusLabel( new KSqueezedTextLabel( this ) )
66 {
67  setPluginLoadingMode( DoNotLoadPlugins );
68 
69  // set the shell's ui resource file
70  setXMLFile(QLatin1String("akregator_shell.rc"));
71 
72  KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); // options_configure_keybinding
73  KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); // options_configure_toolbars
74 
75  toolBar()->show();
76  statusBar()->show();
77 
78  int statH=fontMetrics().height()+2;
79  m_statusLabel->setTextFormat(Qt::RichText);
80  m_statusLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
81  m_statusLabel->setMinimumWidth( 0 );
82  m_statusLabel->setFixedHeight( statH );
83  statusBar()->addWidget( m_statusLabel, 1 );
84 
85  KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
86  KStandardAction::showMenubar( menuBar(), SLOT(setVisible(bool)), actionCollection());
87  setStandardToolBarMenuEnabled(true);
88  createStandardStatusBarAction();
89 
90  connect( KPIM::BroadcastStatus::instance(), SIGNAL(statusMsg(QString)),
91  this, SLOT(slotSetStatusBarText(QString)) );
92 }
93 
94 bool MainWindow::loadPart()
95 {
96  if ( m_part )
97  return true;
98  // this routine will find and load our Part. it finds the Part by
99  // name which is a bad idea usually.. but it's alright in this
100  // case since our Part is made for this Shell
101  KPluginLoader loader(QLatin1String("akregatorpart"));
102  KPluginFactory* const factory = loader.factory();
103  if (!factory) {
104  KMessageBox::error(this, i18n("Could not find the Akregator part; please check your installation.\n%1", loader.errorString()) );
105  return false;
106  }
107 
108  m_part = static_cast<Akregator::Part*>( factory->create<KParts::ReadOnlyPart>(this) );
109 
110  if ( !m_part )
111  return false;
112 
113  m_part->setObjectName(QLatin1String("akregator_part"));
114  setCentralWidget(m_part->widget());
115 
116  connect(m_part, SIGNAL(setWindowCaption(QString)), this, SLOT(setCaption(QString)) );
117 
118  createGUI(m_part);
119  browserExtension(m_part)->setBrowserInterface(m_browserIface);
120  setAutoSaveSettings();
121  return true;
122 }
123 
124 void MainWindow::setupProgressWidgets()
125 {
126  KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( statusBar(), this );
127  progressDialog->raise();
128  progressDialog->hide();
129  m_progressBar = new KPIM::StatusbarProgressWidget( progressDialog, statusBar() );
130  m_progressBar->show();
131  statusBar()->addPermanentWidget( m_progressBar, 0 );
132 }
133 
134 MainWindow::~MainWindow()
135 {
136 }
137 
138 void MainWindow::saveProperties(KConfigGroup &config)
139 {
140  if (!m_part)
141  loadPart();
142 
143  m_part->saveProperties(config);
144  config.writeEntry("docked", isHidden());
145 }
146 
147 void MainWindow::readProperties(const KConfigGroup & config)
148 {
149  if (!m_part)
150  loadPart();
151  m_part->readProperties(config);
152  setVisible( !Settings::showTrayIcon() || !config.readEntry("docked", false) );
153 }
154 
155 // TODO: move to part?
156 void MainWindow::optionsConfigureKeys()
157 {
158  KShortcutsDialog dlg( KShortcutsEditor::AllActions,
159  KShortcutsEditor::LetterShortcutsAllowed, this );
160 
161  dlg.addCollection(actionCollection());
162  if (m_part)
163  dlg.addCollection(m_part->actionCollection());
164 
165  dlg.configure();
166 }
167 
168 // TODO: move to part?
169 void MainWindow::optionsConfigureToolbars()
170 {
171  saveMainWindowSettings(KGlobal::config().data()->group( autoSaveGroup()) );
172  KEditToolBar dlg(factory());
173  connect(&dlg, SIGNAL(newToolBarConfig()),
174  this, SLOT(applyNewToolbarConfig()));
175  dlg.exec();
176 }
177 
178 // TODO: move to part?
179 void MainWindow::applyNewToolbarConfig()
180 {
181  applyMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) );
182 }
183 
184 KParts::BrowserExtension *MainWindow::browserExtension(KParts::ReadOnlyPart *p)
185 {
186  return KParts::BrowserExtension::childObject( p );
187 }
188 
189 bool MainWindow::queryExit()
190 {
191  if ( !kapp->sessionSaving() )
192  {
193  delete m_part; // delete that here instead of dtor to ensure nested khtmlparts are deleted before singleton objects like KHTMLPageCache
194  }
195  return KMainWindow::queryExit();
196 }
197 
198 void MainWindow::slotQuit()
199 {
200  kapp->quit();
201 }
202 
203 bool MainWindow::queryClose()
204 {
205  if ( kapp->sessionSaving() || !TrayIcon::getInstance() )
206  return true;
207  hide();
208  return false;
209 }
210 
211 void MainWindow::slotClearStatusText()
212 {
213  m_statusLabel->setText(QString());
214 }
215 
216 void MainWindow::slotSetStatusBarText( const QString & text )
217 {
218  m_statusLabel->setText(text);
219 }
220 
221 #include "mainwindow.moc"
Akregator::MainWindow::setupProgressWidgets
void setupProgressWidgets()
Creates the progress widget in the status bar and the ProgressDialog and connects them...
Definition: mainwindow.cpp:124
Akregator::MainWindow::~MainWindow
~MainWindow()
Definition: mainwindow.cpp:134
QWidget
Akregator::Part
This is a RSS Aggregator "Part".
Definition: akregator_part.h:76
Akregator::Settings::showTrayIcon
static bool showTrayIcon()
Get Show tray icon.
Definition: akregatorconfig.h:600
Akregator::MainWindow::readProperties
void readProperties(const KConfigGroup &)
This method is called when this app is restored.
Definition: mainwindow.cpp:147
Akregator::MainWindow::slotSetStatusBarText
void slotSetStatusBarText(const QString &c)
Definition: mainwindow.cpp:216
Akregator::MainWindow::queryClose
bool queryClose()
Reimplemented to say if app will be running in system tray if necessary.
Definition: mainwindow.cpp:203
Akregator::MainWindow::slotClearStatusText
void slotClearStatusText()
Definition: mainwindow.cpp:211
akregatorconfig.h
Akregator::BrowserInterface
Definition: mainwindow.h:49
akregator_part.h
mainwindow.h
trayicon.h
Akregator::MainWindow::loadPart
bool loadPart()
Loads the part.
Definition: mainwindow.cpp:94
Akregator::TrayIcon::getInstance
static TrayIcon * getInstance()
Definition: trayicon.cpp:47
Akregator::MainWindow
This is the application "Shell".
Definition: mainwindow.h:67
Akregator::MainWindow::queryExit
bool queryExit()
Reimplemented to save settings.
Definition: mainwindow.cpp:189
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:138
Akregator::BrowserInterface::BrowserInterface
BrowserInterface(Akregator::MainWindow *shell, const char *name)
Definition: mainwindow.cpp:53
Akregator::MainWindow::slotQuit
void slotQuit()
Definition: mainwindow.cpp:198
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 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

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