File indexing completed on 2024-05-12 16:39:24

0001 /* This file is part of the KDE project
0002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0003    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
0004    Copyright (C) 2000-2005 David Faure <faure@kde.org>
0005    Copyright (C) 2005, 2006 Sven Lüppken <sven@kde.org>
0006    Copyright (C) 2008 - 2009, 2012 Dag Andersen <danders@get2net.dk>
0007 
0008    This program is free software; you can redistribute it and/or
0009    modify it under the terms of the GNU General Public
0010    License as published by the Free Software Foundation; either
0011    version 2 of the License, or (at your option) any later version.
0012 
0013    This program is distributed in the hope that it will be useful,
0014    but WITHOUT ANY WARRANTY; without even the implied warranty of
0015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     General Public License for more details.
0017 
0018    You should have received a copy of the GNU General Public License
0019    along with this program; see the file COPYING.  If not, write to
0020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021  * Boston, MA 02110-1301, USA.
0022 */
0023 
0024 // clazy:excludeall=qstring-arg
0025 #include "mainwindow.h"
0026 #include "part.h"
0027 #include "view.h"
0028 
0029 #include "kptdocuments.h"
0030 
0031 #include <QSplitter>
0032 #include <QLabel>
0033 #include <QWidget>
0034 #include <QFileDialog>
0035 #include <QApplication>
0036 
0037 #include <kundo2qstack.h>
0038 
0039 #include <assert.h>
0040 //#include "koshellsettings.h"
0041 
0042 #include <KoDocument.h>
0043 
0044 #include <KLocalizedString>
0045 #include <kmessagebox.h>
0046 #include <kactioncollection.h>
0047 
0048 #include <ktoolinvocation.h>
0049 #include <KIO/StatJob>
0050 #include <kxmlguiwindow.h>
0051 
0052 #include <KoDocumentInfo.h>
0053 #include <KoView.h>
0054 #include <KoFilterManager.h>
0055 
0056 #include "debugarea.h"
0057 
0058 KPlatoWork_MainWindow::KPlatoWork_MainWindow()
0059     : KParts::MainWindow()
0060 {
0061     debugPlanWork<<this;
0062 
0063     m_part = new KPlatoWork::Part(this, this);
0064 
0065     KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
0066  
0067     KStandardAction::open(this, SLOT(slotFileOpen()), actionCollection());
0068 
0069 //     KStandardAction::save(this, SLOT(slotFileSave()), actionCollection());
0070 
0071     QAction *a = KStandardAction::undo(m_part->undoStack(), SLOT(undo()), actionCollection());
0072     a->setEnabled(false);
0073     connect(m_part->undoStack(), &KUndo2QStack::canUndoChanged, a, &QAction::setEnabled);
0074 
0075     a = KStandardAction::redo(m_part->undoStack(), SLOT(redo()), actionCollection());
0076     a->setEnabled(false);
0077     connect(m_part->undoStack(), &KUndo2QStack::canRedoChanged, a, &QAction::setEnabled);
0078     
0079     setCentralWidget(m_part->widget());
0080     setupGUI(KXmlGuiWindow::ToolBar | KXmlGuiWindow::Keys | KXmlGuiWindow::StatusBar | KXmlGuiWindow::Save);
0081     createGUI(m_part);
0082     connect(m_part, SIGNAL(captionChanged(QString,bool)), SLOT(setCaption(QString,bool)));
0083 }
0084 
0085 
0086 KPlatoWork_MainWindow::~KPlatoWork_MainWindow()
0087 {
0088     debugPlanWork;
0089 }
0090 
0091 void KPlatoWork_MainWindow::setCaption(const QString &)
0092 {
0093     KParts::MainWindow::setCaption(QString());
0094 }
0095 
0096 void KPlatoWork_MainWindow::setCaption(const QString &, bool modified)
0097 {
0098     KParts::MainWindow::setCaption(QString(), modified);
0099 }
0100 
0101 bool KPlatoWork_MainWindow::openDocument(const QUrl & url)
0102 {
0103     // TODO: m_part->openUrl will find out about this as well, no?
0104     KIO::StatJob* statJob = KIO::stat(url);
0105     statJob->setSide(KIO::StatJob::SourceSide);
0106 
0107     const bool isUrlReadable = statJob->exec();
0108 
0109     if (! isUrlReadable) {
0110         KMessageBox::error(0L, i18n("The file %1 does not exist.", url.url()));
0111 //        d->recent->removeUrl(url); //remove the file from the recent-opened-file-list
0112 //        saveRecentFiles();
0113         return false;
0114     }
0115     return m_part->openUrl(url);
0116 }
0117 
0118 QString KPlatoWork_MainWindow::configFile() const
0119 {
0120   //return readConfigFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation "koshell/koshell_shell.rc"));
0121   return QString(); // use UI standards only for now
0122 }
0123 
0124 //called from slotFileSave(), slotFileSaveAs(), queryClose(), slotEmailFile()
0125 bool KPlatoWork_MainWindow::saveDocument(bool saveas, bool silent)
0126 {
0127     debugPlanWork<<saveas<<silent;
0128     KPlatoWork::Part *doc = rootDocument();
0129     if (doc == 0) {
0130         return true;
0131     }
0132     return doc->saveWorkPackages(silent);
0133 }
0134 
0135 
0136 bool KPlatoWork_MainWindow::queryClose()
0137 {
0138     KPlatoWork::Part *part = rootDocument();
0139     if (part == 0) {
0140         return true;
0141     }
0142     return part->queryClose();
0143 }
0144 
0145 void KPlatoWork_MainWindow::slotFileClose()
0146 {
0147     if (queryClose()) {
0148     }
0149 }
0150 
0151 void KPlatoWork_MainWindow::slotFileSave()
0152 {
0153     saveDocument();
0154 }
0155 
0156 void KPlatoWork_MainWindow::slotFileOpen()
0157 {
0158     const QUrl file = QFileDialog::getOpenFileUrl(0, QString(), QUrl(), "*.planwork");
0159     if (! file.isEmpty()) {
0160         openDocument(file);
0161     }
0162 }