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 KLibFactory
*factory
= KLibLoader::self()->factory("ktimetrackerpart");
63 // now that the Part is loaded, we cast it to a Part to get
65 m_part
= static_cast<ktimetrackerpart
*>(factory
->create(this, "ktimetrackerpart" ));
69 // tell the KParts::MainWindow that this is indeed
71 setCentralWidget(m_part
->widget());
72 m_part
->openFile(icsfile
);
73 slotSetCaption( icsfile
); // set the window title to our iCal file
74 connect(configureAction
, SIGNAL(triggered(bool)),
75 m_part
->widget(), SLOT(showSettingsDialog()));
76 ((TimetrackerWidget
*) (m_part
->widget()))->setupActions( actionCollection() );
82 // if we couldn't find our Part, we exit since the Shell by
83 // itself can't do anything useful
84 KMessageBox::error(this, i18n( "Could not find the KTimeTracker part." ));
86 // we return here, cause qApp->quit() only means "exit the
87 // next time we enter the event loop...
90 setWindowFlags( windowFlags() | Qt::WindowContextHelpButtonHint
);
93 connect( m_part
->widget(), SIGNAL( statusBarTextChangeRequested( QString
) ),
94 this, SLOT( setStatusBar( QString
) ) );
95 connect( m_part
->widget(), SIGNAL( setCaption( const QString
& ) ),
96 this, SLOT( slotSetCaption( const QString
& ) ) );
99 // Setup context menu request handling
100 connect( m_part
->widget(),
101 SIGNAL( contextMenuRequested( const QPoint
& ) ),
103 SLOT( taskViewCustomContextMenuRequested( const QPoint
& ) ) );
105 _tray
= new TrayIcon( this );
107 connect( _tray
, SIGNAL( quitSelected() ), m_part
->widget(), SLOT( quit() ) );
109 connect( m_part
->widget(), SIGNAL( timersActive() ), _tray
, SLOT( startClock() ) );
110 connect( m_part
->widget(), SIGNAL( timersInactive() ), _tray
, SLOT( stopClock() ) );
111 connect( m_part
->widget(), SIGNAL( tasksChanged( const QList
<Task
*>& ) ),
112 _tray
, SLOT( updateToolTip( QList
<Task
*> ) ));
115 void MainWindow::setupActions()
117 configureAction
= new KAction(this);
118 configureAction
->setText(i18n("Configure KTimeTracker..."));
119 actionCollection()->addAction("configure_ktimetracker", configureAction
);
122 void MainWindow::readProperties( const KConfigGroup
&cfg
)
124 if( cfg
.readEntry( "WindowShown", true ))
128 void MainWindow::saveProperties( KConfigGroup
&cfg
)
130 cfg
.writeEntry( "WindowShown", isVisible());
133 void MainWindow::slotSetCaption( const QString
& qs
)
138 void MainWindow::setStatusBar(const QString
& qs
)
140 statusBar()->showMessage(i18n(qs
.toUtf8()));
143 MainWindow::~MainWindow()
145 kDebug(5970) << "MainWindow::~MainWindows: Quitting ktimetracker.";
149 void MainWindow::keyBindings()
151 KShortcutsDialog::configure( actionCollection(), KShortcutsEditor::LetterShortcutsAllowed
, this );
154 void MainWindow::makeMenus()
156 mainWidget
->setupActions( actionCollection() );
157 actionKeyBindings
= KStandardAction::keyBindings( this, SLOT( keyBindings() ),
158 actionCollection() );
160 actionKeyBindings
->setToolTip( i18n( "Configure key bindings" ) );
161 actionKeyBindings
->setWhatsThis( i18n( "This will let you configure key"
162 "bindings which are specific to ktimetracker" ) );
165 void MainWindow::loadGeometry()
167 if (initialGeometrySet()) setAutoSaveSettings();
170 KConfigGroup config
= KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
171 int w
= config
.readEntry( QString::fromLatin1("Width"), 100 );
172 int h
= config
.readEntry( QString::fromLatin1("Height"), 100 );
173 w
= qMax( w
, sizeHint().width() );
174 h
= qMax( h
, sizeHint().height() );
180 void MainWindow::saveGeometry()
182 KConfigGroup config
= KGlobal::config()->group( QString::fromLatin1("Main Window Geometry") );
183 config
.writeEntry( QString::fromLatin1("Width"), width());
184 config
.writeEntry( QString::fromLatin1("Height"), height());
188 bool MainWindow::queryClose()
190 if ( !kapp
->sessionSaving() )
195 return KMainWindow::queryClose();
198 void MainWindow::taskViewCustomContextMenuRequested( const QPoint
& point
)
200 QMenu
* pop
= dynamic_cast<QMenu
*>( factory()->container( i18n( "task_popup" ), this ) );
205 #include "mainwindow.moc"