File indexing completed on 2024-12-01 03:37:20

0001 /*
0002     SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #ifndef PARLEYDOCUMENT_H
0006 #define PARLEYDOCUMENT_H
0007 
0008 #include <KEduVocDocument>
0009 #include <KNSWidgets/Button>
0010 #include <QObject>
0011 #include <memory>
0012 
0013 #include <config-parley.h>
0014 
0015 class ParleyMainWindow;
0016 class QTimer;
0017 
0018 /**
0019     @author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0020 */
0021 class ParleyDocument : public QObject
0022 {
0023     Q_OBJECT
0024 public:
0025     explicit ParleyDocument(ParleyMainWindow *parleyMainWindow);
0026     ~ParleyDocument() override;
0027 
0028     std::shared_ptr<KEduVocDocument> document();
0029 
0030     void setTitle(const QString &title);
0031 
0032     /** Enable/disable the timed auto backup
0033      @todo Move autobackup functionality into libkdeedu which is responsible for
0034     file opening/closing and locking already.*/
0035     void enableAutoBackup(bool enable);
0036     // void fetchGrammar(int languageIndex);
0037 
0038 public Q_SLOTS:
0039     /** open a new application window */
0040     void slotFileNew();
0041 
0042     /** open a document */
0043     void slotFileOpen();
0044 
0045     /** opens a file from the recent files menu */
0046     void slotFileOpenRecent(const QUrl &url);
0047     /** open a downloaded (knewstuff/get hot new stuff) document */
0048     void openGHNS();
0049     /** download new vocabularies */
0050     void slotGHNS(const QList<KNSCore::Entry> &entries);
0051 
0052     /** Opens the given url, displays an error message and returns false on failure */
0053     bool open(const QUrl &);
0054 
0055     /** close the document*/
0056     void close();
0057     /** When quitting, ask for confirmation if the doc has not been saved */
0058     bool queryClose();
0059 
0060     /** merge a document */
0061     void slotFileMerge();
0062     /** save a document */
0063     void save();
0064     void saveAs(QUrl file = QUrl());
0065 
0066     void exportDialog();
0067 
0068     void newDocument(bool wizard);
0069 
0070     /** General doc properties like title, author etc */
0071     void documentProperties();
0072     void languageProperties();
0073 
0074 Q_SIGNALS:
0075     /** Emitted when the document pointer is changed.
0076      @todo Stop using documentChanged(0) as a replacement for destroyed in editor classes.**/
0077     void documentChanged(const std::shared_ptr<KEduVocDocument> &newDocument);
0078     void languagesChanged();
0079     void statesNeedSaving();
0080 
0081 private:
0082     void initializeDefaultGrammar(KEduVocDocument *doc);
0083     void setDefaultDocumentProperties(KEduVocDocument *doc);
0084 
0085 private:
0086     ParleyMainWindow *m_parleyApp{nullptr}; // Pointer to the owner of this document
0087     QTimer *m_backupTimer{nullptr}; // Timer for next autosave
0088 
0089     // The contents of the document
0090     std::shared_ptr<KEduVocDocument> m_doc;
0091 };
0092 
0093 #endif