File indexing completed on 2024-04-14 05:41:09

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #ifndef BNPVIEW_H
0007 #define BNPVIEW_H
0008 
0009 #include <QSplitter>
0010 #include <QXmlStreamWriter>
0011 #include <QtCore/QList>
0012 #include <QtGui/QClipboard>
0013 
0014 #include <KXMLGUIClient>
0015 
0016 #include "basket_export.h"
0017 #include "global.h"
0018 #include <memory>
0019 
0020 class QDomElement;
0021 
0022 class QStackedWidget;
0023 class QPixmap;
0024 class QTimer;
0025 class QTreeWidget;
0026 class QTreeWidgetItem;
0027 class QUndoStack;
0028 
0029 class QEvent;
0030 class QShowEvent;
0031 
0032 class QAction;
0033 class KToggleAction;
0034 class QMenu;
0035 class KTar;
0036 
0037 class ColorPicker;
0038 class RegionGrabber;
0039 
0040 class BasketScene;
0041 class DecoratedBasket;
0042 class BasketListViewItem;
0043 class BasketTreeListView;
0044 class NoteSelection;
0045 class BasketStatusBar;
0046 class Tag;
0047 class State;
0048 class Note;
0049 class KMainWindow;
0050 class KMessageWidget;
0051 
0052 class BASKET_EXPORT BNPView : public QSplitter
0053 {
0054     Q_OBJECT
0055     Q_CLASSINFO("D Bus Interface", "org.kde.basket.dbus");
0056 
0057 public:
0058     /// CONSTRUCTOR AND DESTRUCTOR:
0059     BNPView(QWidget *parent, const char *name, KXMLGUIClient *aGUIClient, KActionCollection *actionCollection, BasketStatusBar *bar);
0060     ~BNPView() override;
0061     /// MANAGE CONFIGURATION EVENTS!:
0062     void setTreePlacement(bool onLeft);
0063     void relayoutAllBaskets();
0064     void recomputeAllStyles();
0065     void removedStates(const QList<State *> &deletedStates);
0066     void linkLookChanged();
0067     void filterPlacementChanged(bool onTop);
0068     /// MANAGE BASKETS:
0069     BasketListViewItem *listViewItemForBasket(BasketScene *basket);
0070     BasketScene *currentBasket();
0071     BasketScene *parentBasketOf(BasketScene *basket);
0072     void setCurrentBasket(BasketScene *basket);
0073     void setCurrentBasketInHistory(BasketScene *basket);
0074     void removeBasket(BasketScene *basket);
0075     /// For NewBasketDialog (and later some other classes):
0076     int topLevelItemCount();
0077     ///
0078     BasketListViewItem *topLevelItem(int i);
0079     int basketCount(QTreeWidgetItem *parent = nullptr);
0080     bool canFold();
0081     bool canExpand();
0082     void enableActions();
0083 
0084 private:
0085     //! Create <basket> element with <properties>
0086     void writeBasketElement(QTreeWidgetItem *item, QXmlStreamWriter &steam);
0087 public Q_SLOTS:
0088     void countsChanged(BasketScene *basket);
0089     void notesStateChanged();
0090     bool convertTexts();
0091 
0092     void updateBasketListViewItem(BasketScene *basket);
0093     void save();
0094     void save(QTreeWidget *listView, QTreeWidgetItem *firstItem, QXmlStreamWriter &stream);
0095     void saveSubHierarchy(QTreeWidgetItem *item, QXmlStreamWriter &stream, bool recursive);
0096     void load();
0097     void load(QTreeWidgetItem *item, const QDomElement &baskets);
0098     void loadNewBasket(const QString &folderName, const QDomElement &properties, BasketScene *parent);
0099     void goToPreviousBasket();
0100     void goToNextBasket();
0101     void foldBasket();
0102     void expandBasket();
0103     void closeAllEditors();
0104     ///
0105     void toggleFilterAllBaskets(bool doFilter);
0106     void newFilter();
0107     void newFilterFromFilterBar();
0108     bool isFilteringAllBaskets();
0109     // From main window
0110     void importTextFile();
0111     void backupRestore();
0112     void checkCleanup();
0113 
0114     /** Note */
0115     void activatedTagShortcut();
0116     void exportToHTML();
0117     void editNote();
0118     void cutNote();
0119     void copyNote();
0120     void delNote();
0121     void clearFormattingNote();
0122     void openNote();
0123     void openNoteWith();
0124     void saveNoteAs();
0125     void noteGroup();
0126     void noteUngroup();
0127     void moveOnTop();
0128     void moveOnBottom();
0129     void moveNoteUp();
0130     void moveNoteDown();
0131     void slotSelectAll();
0132     void slotUnselectAll();
0133     void slotInvertSelection();
0134     void slotResetFilter();
0135 
0136     void slotColorFromScreen(bool global = false);
0137     void slotColorFromScreenGlobal();
0138     void colorPicked(const QColor &color);
0139     void slotConvertTexts();
0140 
0141     /** Global shortcuts */
0142     void addNoteText();
0143     void addNoteHtml();
0144     void addNoteImage();
0145     void addNoteLink();
0146     void addNoteCrossReference();
0147     void addNoteColor();
0148     /** Passive Popups for Global Actions */
0149     // For GUI :
0150     void setFiltering(bool filtering);
0151     /** Edit */
0152     void undo();
0153     void redo();
0154     void globalPasteInCurrentBasket();
0155     void pasteInCurrentBasket();
0156     void pasteSelInCurrentBasket();
0157     void pasteToBasket(int index, QClipboard::Mode mode = QClipboard::Clipboard);
0158     void showHideFilterBar(bool show, bool switchFocus = true);
0159     /** Insert **/
0160     void insertEmpty(int type);
0161     void insertWizard(int type);
0162     void grabScreenshot(bool global = false);
0163     void grabScreenshotGlobal();
0164     void screenshotGrabbed(const QPixmap &pixmap);
0165     /** BasketScene */
0166     void askNewBasket();
0167     void askNewBasket(BasketScene *parent, BasketScene *pickProperties);
0168     void askNewSubBasket();
0169     void askNewSiblingBasket();
0170     void aboutToHideNewBasketPopup();
0171     void setNewBasketPopup();
0172     void cancelNewBasketPopup();
0173     void propBasket();
0174     void delBasket();
0175     void doBasketDeletion(BasketScene *basket);
0176     void password();
0177     void saveAsArchive();
0178     void openArchive();
0179     void delayedOpenArchive();
0180     void delayedOpenBasket();
0181     void lockBasket();
0182 
0183     void changedSelectedNotes();
0184 
0185     void loadCrossReference(QString link);
0186 
0187     //Returns an empty string to indicate failure to find a corresponding basket
0188     QString folderFromBasketNameLink(QStringList pages, QTreeWidgetItem *parent = nullptr);
0189 
0190     void sortChildrenAsc();
0191     void sortChildrenDesc();
0192     void sortSiblingsAsc();
0193     void sortSiblingsDesc();
0194 
0195 public:
0196     static QString s_fileToOpen;
0197     static QString s_basketToOpen;
0198 
0199 public Q_SLOTS:
0200     void addWelcomeBaskets();
0201 private Q_SLOTS:
0202     void updateNotesActions();
0203     void slotBasketChanged();
0204     void canUndoRedoChanged();
0205     void currentBasketChanged();
0206     void isLockedChanged();
0207     void lateInit();
0208     void onFirstShow();
0209 
0210 public:
0211     QAction *m_actClearFormatting;
0212     QAction *m_actEditNote;
0213     QAction *m_actOpenNote;
0214     QAction *m_actPaste;
0215     QAction *m_actGrabScreenshot;
0216     QAction *m_actColorPicker;
0217     QAction *m_actLockBasket;
0218     QAction *m_actPassBasket;
0219     QAction *actNewBasket;
0220     QAction *actNewSubBasket;
0221     QAction *actNewSiblingBasket;
0222     QAction *m_actExportToHtml;
0223     QAction *m_actPropBasket;
0224     QAction *m_actSortChildrenAsc;
0225     QAction *m_actSortChildrenDesc;
0226     QAction *m_actSortSiblingsAsc;
0227     QAction *m_actSortSiblingsDesc;
0228     QAction *m_actDelBasket;
0229     KToggleAction *m_actFilterAllBaskets;
0230 
0231 private:
0232     // Basket actions:
0233     QAction *m_actSaveAsArchive;
0234     QAction *m_actOpenArchive;
0235     // Notes actions :
0236     QAction *m_actOpenNoteWith;
0237     QAction *m_actSaveNoteAs;
0238     QAction *m_actGroup;
0239     QAction *m_actUngroup;
0240     QAction *m_actMoveOnTop;
0241     QAction *m_actMoveNoteUp;
0242     QAction *m_actMoveNoteDown;
0243     QAction *m_actMoveOnBottom;
0244     // Edit actions :
0245     QAction *m_actUndo;
0246     QAction *m_actRedo;
0247     QAction *m_actCutNote;
0248     QAction *m_actCopyNote;
0249     QAction *m_actDelNote;
0250     QAction *m_actSelectAll;
0251     QAction *m_actUnselectAll;
0252     QAction *m_actInvertSelection;
0253     // Insert actions :
0254     //      QAction *m_actInsertText;
0255     QAction *m_actInsertHtml;
0256     QAction *m_actInsertLink;
0257     QAction *m_actInsertCrossReference;
0258     QAction *m_actInsertImage;
0259     QAction *m_actInsertColor;
0260     QAction *m_actImportKMenu;
0261     QAction *m_actInsertLauncher;
0262     QAction *m_actImportIcon;
0263     QAction *m_actLoadFile;
0264     QList<QAction *> m_insertActions;
0265     // Basket actions :
0266     KToggleAction *m_actShowFilter;
0267     QAction *m_actResetFilter;
0268     // Go actions :
0269     QAction *m_actPreviousBasket;
0270     QAction *m_actNextBasket;
0271     QAction *m_actFoldBasket;
0272     QAction *m_actExpandBasket;
0273     //      QAction *m_convertTexts; // FOR_BETA_PURPOSE
0274 
0275     void setupActions();
0276     void setupGlobalShortcuts();
0277     DecoratedBasket *currentDecoratedBasket();
0278 
0279 public:
0280     BasketScene *loadBasket(const QString &folderName);                                 // Public only for class Archive
0281     BasketListViewItem *appendBasket(BasketScene *basket, QTreeWidgetItem *parentItem); // Public only for class Archive
0282 
0283     BasketScene *basketForFolderName(const QString &folderName);
0284     Note *noteForFileName(const QString &fileName, BasketScene &basket, Note *note = nullptr);
0285     QMenu *popupMenu(const QString &menuName);
0286     bool isMainWindowActive();
0287     void showMainWindow();
0288 
0289     // TODO: dcop calls -- dbus these
0290 public Q_SLOTS:
0291     Q_SCRIPTABLE void newBasket();
0292     Q_SCRIPTABLE void handleCommandLine();
0293     Q_SCRIPTABLE void reloadBasket(const QString &folderName);
0294     Q_SCRIPTABLE bool createNoteHtml(const QString content, const QString basket);
0295     Q_SCRIPTABLE QStringList listBaskets();
0296     Q_SCRIPTABLE bool createNoteFromFile(const QString url, const QString basket);
0297     Q_SCRIPTABLE bool changeNoteHtml(const QString content, const QString basket, const QString noteName);
0298 
0299 public Q_SLOTS:
0300     void setWindowTitle(QString s);
0301     void updateStatusBarHint();
0302     void setSelectionStatus(QString s);
0303     void setLockStatus(bool isLocked);
0304     void postStatusbarMessage(const QString &);
0305     void setStatusBarHint(const QString &);
0306     void setUnsavedStatus(bool isUnsaved);
0307     void setActive(bool active = true);
0308     KActionCollection *actionCollection()
0309     {
0310         return m_actionCollection;
0311     };
0312 
0313     void populateTagsMenu();
0314     void populateTagsMenu(QMenu &menu, Note *referenceNote);
0315     void connectTagsMenu();
0316     void disconnectTagsMenu();
0317     void disconnectTagsMenuDelayed();
0318 
0319 protected:
0320     void showEvent(QShowEvent *) override;
0321 
0322 private:
0323     QMenu *m_lastOpenedTagsMenu;
0324 
0325 private Q_SLOTS:
0326     void slotPressed(QTreeWidgetItem *item, int column);
0327     void needSave(QTreeWidgetItem *);
0328     void slotContextMenu(const QPoint &pos);
0329     void slotShowProperties(QTreeWidgetItem *item);
0330     void initialize();
0331 
0332 Q_SIGNALS:
0333     void basketChanged();
0334     void setWindowCaption(const QString &s);
0335     void showPart();
0336     void showErrorMessage(const QString &message);
0337 
0338 protected:
0339     void hideMainWindow();
0340 
0341 private:
0342     BasketTreeListView *m_tree;
0343     QStackedWidget *m_stack;
0344     bool m_loading;
0345     bool m_newBasketPopup;
0346     bool m_firstShow;
0347 #ifndef _WIN32
0348     ColorPicker *m_colorPicker;
0349 #endif
0350     bool m_colorPickWasShown;
0351     bool m_colorPickWasGlobal;
0352     RegionGrabber *m_regionGrabber;
0353     QString m_passiveDroppedTitle;
0354     NoteSelection *m_passiveDroppedSelection;
0355     static const int c_delayTooltipTime;
0356     KActionCollection *m_actionCollection;
0357     KXMLGUIClient *m_guiClient;
0358     BasketStatusBar *m_statusbar;
0359 
0360     QUndoStack *m_history;
0361     KMainWindow *m_HiddenMainWindow;
0362 };
0363 
0364 #endif // BNPVIEW_H