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

ktimetracker

  • sources
  • kde-4.12
  • kdepim
  • ktimetracker
mainwindow.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 by Scott Monachello <smonach@cox.net>
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 along
15  * with this program; if not, write to the
16  * Free Software Foundation, Inc.
17  * 51 Franklin Street, Fifth Floor
18  * Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #include "mainwindow.h"
23 
24 #include <numeric>
25 
26 #include <QMenu>
27 #include <QString>
28 #include <QTimer>
29 
30 #include <KAction>
31 #include <KApplication> // kapp
32 #include <KDebug>
33 #include <KGlobal>
34 #include <KIcon>
35 #include <KLocale> // i18n
36 #include <KMessageBox>
37 #include <KPushButton>
38 #include <KShortcutsDialog>
39 #include <KStandardAction>
40 #include <KStatusBar> // statusBar()
41 #include <KXMLGUIFactory>
42 #include <KActionCollection>
43 #include <KPluginLoader>
44 #include <KPluginFactory>
45 
46 #include "ktimetrackerutility.h"
47 #include "ktimetracker.h"
48 #include "task.h"
49 #include "taskview.h"
50 #include "timekard.h"
51 #include "tray.h"
52 
53 #include "timetrackerwidget.h"
54 
55 MainWindow::MainWindow( const QString &icsfile )
56  : KParts::MainWindow( )
57 {
58  kDebug(5970) << "Entering function, icsfile is " << icsfile;
59  // Setup our actions
60  setupActions();
61 
62  // this routine will find and load our Part.
63  KPluginLoader loader( "ktimetrackerpart" );
64  KPluginFactory *factory = loader.factory();
65  if (factory)
66  {
67  // now that the Part is loaded, we cast it to a Part to get our hands on it
68 
69  //NOTE: Use the dynamic_cast below. Without it, KPluginLoader will use a qobject_cast
70  // that fails, because ktimetrackerpart is defined twice, once in ktimetracker's binary
71  // and another one in the plugin. The build system should be fixed.
72  //m_part = factory->create<ktimetrackerpart>( this );
73 
74  m_part = dynamic_cast<ktimetrackerpart*>( factory->create<KParts::ReadWritePart>( this ) );
75 
76  if (m_part)
77  {
78  // tell the KParts::MainWindow that this is indeed
79  // the main widget
80  setCentralWidget(m_part->widget());
81  m_part->openFile(icsfile);
82  slotSetCaption( icsfile ); // set the window title to our iCal file
83  connect(configureAction, SIGNAL(triggered(bool)),
84  m_part->widget(), SLOT(showSettingsDialog()));
85  ((TimetrackerWidget *) (m_part->widget()))->setupActions( actionCollection() );
86  setupGUI();
87  }
88  else
89  {
90  kError() << "Could not find the KTimeTracker part: m_part is 0";
91  KMessageBox::error(this, i18n( "Could not create the KTimeTracker part." ));
92  QTimer::singleShot(0, qApp, SLOT(quit()));
93  return;
94  }
95  }
96  else
97  {
98  // if we couldn't find our Part, we exit since the Shell by
99  // itself can't do anything useful
100  kError() << "Could not find the KTimeTracker part: factory is 0";
101  KMessageBox::error(this, i18n( "Could not find the KTimeTracker part." ));
102  QTimer::singleShot(0, qApp, SLOT(quit()));
103  // we return here, cause qApp->quit() only means "exit the
104  // next time we enter the event loop...
105  return;
106  }
107  setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint );
108 
109  // connections
110  connect( m_part->widget(), SIGNAL(statusBarTextChangeRequested(QString)),
111  this, SLOT(setStatusBar(QString)) );
112  connect( m_part->widget(), SIGNAL(setCaption(QString)),
113  this, SLOT(slotSetCaption(QString)) );
114  loadGeometry();
115 
116  // Setup context menu request handling
117  connect( m_part->widget(),
118  SIGNAL(contextMenuRequested(QPoint)),
119  this,
120  SLOT(taskViewCustomContextMenuRequested(QPoint)) );
121  if (KTimeTrackerSettings::trayIcon())
122  {
123  _tray = new TrayIcon( this );
124  connect( m_part->widget(), SIGNAL(timersActive()), _tray, SLOT(startClock()) );
125  connect( m_part->widget(), SIGNAL(timersInactive()), _tray, SLOT(stopClock()) );
126  connect( m_part->widget(), SIGNAL(tasksChanged(QList<Task*>)), _tray, SLOT(updateToolTip(QList<Task*>)));
127  }
128 }
129 
130 void MainWindow::setupActions()
131 {
132  configureAction = new KAction(this);
133  configureAction->setText(i18n("Configure KTimeTracker..."));
134  actionCollection()->addAction("configure_ktimetracker", configureAction);
135 }
136 
137 void MainWindow::readProperties( const KConfigGroup &cfg )
138 {
139  if( cfg.readEntry( "WindowShown", true ))
140  show();
141 }
142 
143 void MainWindow::saveProperties( KConfigGroup &cfg )
144 {
145  cfg.writeEntry( "WindowShown", isVisible());
146 }
147 
148 void MainWindow::slotSetCaption( const QString& qs )
149 {
150  setCaption( qs );
151 }
152 
153 void MainWindow::setStatusBar(const QString& qs)
154 {
155  statusBar()->showMessage(i18n(qs.toUtf8()));
156 }
157 
158 MainWindow::~MainWindow()
159 {
160  kDebug(5970) << "MainWindow::~MainWindows: Quitting ktimetracker.";
161  saveGeometry();
162 }
163 
164 void MainWindow::keyBindings()
165 {
166  KShortcutsDialog::configure( actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, this );
167 }
168 
169 void MainWindow::makeMenus()
170 {
171  mainWidget->setupActions( actionCollection() );
172  actionKeyBindings = KStandardAction::keyBindings( this, SLOT(keyBindings()),
173  actionCollection() );
174  setupGUI();
175  actionKeyBindings->setToolTip( i18n( "Configure key bindings" ) );
176  actionKeyBindings->setWhatsThis( i18n( "This will let you configure key"
177  "bindings which are specific to ktimetracker" ) );
178 }
179 
180 void MainWindow::loadGeometry()
181 {
182  if (initialGeometrySet()) setAutoSaveSettings();
183  else
184  {
185  KConfigGroup config = KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
186  int w = config.readEntry( QString::fromLatin1("Width"), 100 );
187  int h = config.readEntry( QString::fromLatin1("Height"), 100 );
188  w = qMax( w, sizeHint().width() );
189  h = qMax( h, sizeHint().height() );
190  resize(w, h);
191  }
192 }
193 
194 
195 void MainWindow::saveGeometry()
196 {
197  KConfigGroup config = KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
198  config.writeEntry( QString::fromLatin1("Width"), width());
199  config.writeEntry( QString::fromLatin1("Height"), height());
200  config.sync();
201 }
202 
203 bool MainWindow::queryClose()
204 {
205  if ( !kapp->sessionSaving() )
206  {
207  hide();
208  return false;
209  }
210  return KMainWindow::queryClose();
211 }
212 
213 void MainWindow::taskViewCustomContextMenuRequested( const QPoint& point )
214 {
215  QMenu* pop = dynamic_cast<QMenu*>( factory()->container( i18n( "task_popup" ), this ) );
216  if ( pop )
217  pop->popup( point );
218 }
219 
220 #include "mainwindow.moc"
timetrackerwidget.h
MainWindow::readProperties
void readProperties(const KConfigGroup &config)
Definition: mainwindow.cpp:137
TimetrackerWidget
Definition: timetrackerwidget.h:36
MainWindow::keyBindings
void keyBindings()
Definition: mainwindow.cpp:164
ktimetrackerpart::openFile
virtual bool openFile()
openFile() opens the icalendar file that contains the tasks and events.
Definition: ktimetrackerpart.cpp:117
KTimeTrackerSettings::trayIcon
static bool trayIcon()
Get trayIcon.
Definition: ktimetracker.h:354
TimetrackerWidget::setupActions
void setupActions(KActionCollection *actionCollection)
initializes the KActionCollection object of a main window for example.
Definition: timetrackerwidget.cpp:200
taskview.h
MainWindow::slotSetCaption
void slotSetCaption(const QString &)
Definition: mainwindow.cpp:148
mainwindow.h
MainWindow::showSettingsDialog
void showSettingsDialog()
Definition: new/mainwindow.cpp:111
ktimetracker.h
tray.h
MainWindow::TrayIcon
friend class TrayIcon
Definition: mainwindow.h:59
MainWindow::queryClose
bool queryClose()
Definition: mainwindow.cpp:203
MainWindow::setStatusBar
void setStatusBar(const QString &)
Definition: mainwindow.cpp:153
task.h
timekard.h
MainWindow::saveGeometry
void saveGeometry()
Definition: mainwindow.cpp:195
ktimetrackerpart
This is a "Part".
Definition: ktimetrackerpart.h:41
MainWindow::~MainWindow
virtual ~MainWindow()
Definition: mainwindow.cpp:158
ktimetrackerutility.h
MainWindow::loadGeometry
void loadGeometry()
Definition: mainwindow.cpp:180
MainWindow::saveProperties
void saveProperties(KConfigGroup &config)
Definition: mainwindow.cpp:143
MainWindow::MainWindow
MainWindow(const QString &icsfile="")
Definition: mainwindow.cpp:55
icsfile
QString icsfile(const KCmdLineArgs *args)
Definition: main.cpp:51
MainWindow::taskViewCustomContextMenuRequested
void taskViewCustomContextMenuRequested(const QPoint &)
Definition: mainwindow.cpp:213
MainWindow
Main window to tie the application together.
Definition: mainwindow.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

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

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