2 * Copyright (C) 2003 by Scott Monachello <smonach@cox.net>
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.
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.
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.
22 #include "mainwindow.h"
31 #include <KApplication> // kapp
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>
46 #include "ktimetrackerutility.h"
47 #include "ktimetracker.h"
53 #include "timetrackerwidget.h"
55 MainWindow::MainWindow( const QString
&icsfile
)
56 : KParts::MainWindow( )
58 kDebug(5970) << "Entering function, icsfile is " << icsfile
;
62 // this routine will find and load our Part.
63 KPluginLoader
loader( "ktimetrackerpart" );
64 KPluginFactory
*factory
= loader
.factory();
67 // now that the Part is loaded, we cast it to a Part to get our hands on it
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 );
74 m_part
= dynamic_cast<ktimetrackerpart
*>( factory
->create
<KParts::ReadWritePart
>( this ) );
78 // tell the KParts::MainWindow that this is indeed
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() );
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()));
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...
107 setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint
);
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
)) );
116 // Setup context menu request handling
117 connect( m_part
->widget(),
118 SIGNAL(contextMenuRequested(QPoint
)),
120 SLOT(taskViewCustomContextMenuRequested(QPoint
)) );
121 if (KTimeTrackerSettings::trayIcon())
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
*>)));
130 void MainWindow::setupActions()
132 configureAction
= new KAction(this);
133 configureAction
->setText(i18n("Configure KTimeTracker..."));
134 actionCollection()->addAction("configure_ktimetracker", configureAction
);
137 void MainWindow::readProperties( const KConfigGroup
&cfg
)
139 if( cfg
.readEntry( "WindowShown", true ))
143 void MainWindow::saveProperties( KConfigGroup
&cfg
)
145 cfg
.writeEntry( "WindowShown", isVisible());
148 void MainWindow::slotSetCaption( const QString
& qs
)
153 void MainWindow::setStatusBar(const QString
& qs
)
155 statusBar()->showMessage(i18n(qs
.toUtf8()));
158 MainWindow::~MainWindow()
160 kDebug(5970) << "MainWindow::~MainWindows: Quitting ktimetracker.";
164 void MainWindow::keyBindings()
166 KShortcutsDialog::configure( actionCollection(), KShortcutsEditor::LetterShortcutsAllowed
, this );
169 void MainWindow::makeMenus()
171 mainWidget
->setupActions( actionCollection() );
172 actionKeyBindings
= KStandardAction::keyBindings( this, SLOT(keyBindings()),
173 actionCollection() );
175 actionKeyBindings
->setToolTip( i18n( "Configure key bindings" ) );
176 actionKeyBindings
->setWhatsThis( i18n( "This will let you configure key"
177 "bindings which are specific to ktimetracker" ) );
180 void MainWindow::loadGeometry()
182 if (initialGeometrySet()) setAutoSaveSettings();
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() );
195 void MainWindow::saveGeometry()
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());
203 bool MainWindow::queryClose()
205 if ( !kapp
->sessionSaving() )
210 return KMainWindow::queryClose();
213 void MainWindow::taskViewCustomContextMenuRequested( const QPoint
& point
)
215 QMenu
* pop
= dynamic_cast<QMenu
*>( factory()->container( i18n( "task_popup" ), this ) );
220 #include "mainwindow.moc"