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"
30 #include <KApplication> // kapp
34 #include <KLocale> // i18n
35 #include <KMessageBox>
36 #include <KPushButton>
37 #include <KShortcutsDialog>
38 #include <KStandardAction>
39 #include <KStatusBar> // statusBar()
40 #include <KXMLGUIFactory>
41 #include <KActionCollection>
43 #include "ktimetrackerutility.h"
44 #include "ktimetracker.h"
50 #include "timetrackerwidget.h"
52 MainWindow::MainWindow( const QString
&icsfile
)
53 : KParts::MainWindow( )
55 kDebug(5970) << "Entering function, icsfile is " << icsfile
;
59 // this routine will find and load our Part.
60 KPluginLoader
loader( "ktimetrackerpart" );
61 KPluginFactory
*factory
= loader
.factory();
64 // now that the Part is loaded, we cast it to a Part to get
66 m_part
= factory
->create
<ktimetrackerpart
>( this );
70 // tell the KParts::MainWindow that this is indeed
72 setCentralWidget(m_part
->widget());
73 m_part
->openFile(icsfile
);
74 slotSetCaption( icsfile
); // set the window title to our iCal file
75 connect(configureAction
, SIGNAL(triggered(bool)),
76 m_part
->widget(), SLOT(showSettingsDialog()));
77 ((TimetrackerWidget
*) (m_part
->widget()))->setupActions( actionCollection() );
83 // if we couldn't find our Part, we exit since the Shell by
84 // itself can't do anything useful
85 KMessageBox::error(this, i18n( "Could not find the KTimeTracker part." ));
87 // we return here, cause qApp->quit() only means "exit the
88 // next time we enter the event loop...
91 setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint
);
94 connect( m_part
->widget(), SIGNAL( statusBarTextChangeRequested( QString
) ),
95 this, SLOT( setStatusBar( QString
) ) );
96 connect( m_part
->widget(), SIGNAL( setCaption( const QString
& ) ),
97 this, SLOT( slotSetCaption( const QString
& ) ) );
100 // Setup context menu request handling
101 connect( m_part
->widget(),
102 SIGNAL( contextMenuRequested( const QPoint
& ) ),
104 SLOT( taskViewCustomContextMenuRequested( const QPoint
& ) ) );
106 _tray
= new TrayIcon( this );
108 connect( _tray
, SIGNAL( quitSelected() ), m_part
->widget(), SLOT( quit() ) );
110 connect( m_part
->widget(), SIGNAL( timersActive() ), _tray
, SLOT( startClock() ) );
111 connect( m_part
->widget(), SIGNAL( timersInactive() ), _tray
, SLOT( stopClock() ) );
112 connect( m_part
->widget(), SIGNAL( tasksChanged( const QList
<Task
*>& ) ),
113 _tray
, SLOT( updateToolTip( QList
<Task
*> ) ));
116 void MainWindow::setupActions()
118 configureAction
= new KAction(this);
119 configureAction
->setText(i18n("Configure KTimeTracker..."));
120 actionCollection()->addAction("configure_ktimetracker", configureAction
);
123 void MainWindow::readProperties( const KConfigGroup
&cfg
)
125 if( cfg
.readEntry( "WindowShown", true ))
129 void MainWindow::saveProperties( KConfigGroup
&cfg
)
131 cfg
.writeEntry( "WindowShown", isVisible());
134 void MainWindow::slotSetCaption( const QString
& qs
)
139 void MainWindow::setStatusBar(const QString
& qs
)
141 statusBar()->showMessage(i18n(qs
.toUtf8()));
144 MainWindow::~MainWindow()
146 kDebug(5970) << "MainWindow::~MainWindows: Quitting ktimetracker.";
150 void MainWindow::keyBindings()
152 KShortcutsDialog::configure( actionCollection(), KShortcutsEditor::LetterShortcutsAllowed
, this );
155 void MainWindow::makeMenus()
157 mainWidget
->setupActions( actionCollection() );
158 actionKeyBindings
= KStandardAction::keyBindings( this, SLOT( keyBindings() ),
159 actionCollection() );
161 actionKeyBindings
->setToolTip( i18n( "Configure key bindings" ) );
162 actionKeyBindings
->setWhatsThis( i18n( "This will let you configure key"
163 "bindings which are specific to ktimetracker" ) );
166 void MainWindow::loadGeometry()
168 if (initialGeometrySet()) setAutoSaveSettings();
171 KConfigGroup config
= KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
172 int w
= config
.readEntry( QString::fromLatin1("Width"), 100 );
173 int h
= config
.readEntry( QString::fromLatin1("Height"), 100 );
174 w
= qMax( w
, sizeHint().width() );
175 h
= qMax( h
, sizeHint().height() );
181 void MainWindow::saveGeometry()
183 KConfigGroup config
= KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
184 config
.writeEntry( QString::fromLatin1("Width"), width());
185 config
.writeEntry( QString::fromLatin1("Height"), height());
189 bool MainWindow::queryClose()
191 if ( !kapp
->sessionSaving() )
196 return KMainWindow::queryClose();
199 void MainWindow::taskViewCustomContextMenuRequested( const QPoint
& point
)
201 QMenu
* pop
= dynamic_cast<QMenu
*>( factory()->container( i18n( "task_popup" ), this ) );
206 #include "mainwindow.moc"