1 /***************************************************************************
2  *   Copyright (C) 2003 by Sébastien Laoût                                 *
3  *   slaout@linux62.org                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 #ifndef BNPVIEW_H
22 #define BNPVIEW_H
23 
24 #include <QtCore/QList>
25 #include <QtGui/QClipboard>
26 #include <QSplitter>
27 #include <QXmlStreamWriter>
28 
29 #include <KXMLGUIClient>
30 
31 #include "global.h"
32 #include "basket_export.h"
33 
34 class QDomElement;
35 
36 class QStackedWidget;
37 class QPixmap;
38 class QTimer;
39 class QTreeWidget;
40 class QTreeWidgetItem;
41 class QUndoStack;
42 
43 class QEvent;
44 class QHideEvent;
45 class QShowEvent;
46 
47 class QAction;
48 class KToggleAction;
49 class QMenu;
50 class KTar;
51 
52 class DesktopColorPicker;
53 class RegionGrabber;
54 
55 class BasketScene;
56 class DecoratedBasket;
57 class BasketListView;
58 class BasketListViewItem;
59 class BasketTreeListView;
60 class NoteSelection;
61 class BasketStatusBar;
62 class Tag;
63 class State;
64 class Note;
65 class KMainWindow;
66 
67 class BASKET_EXPORT BNPView : public QSplitter
68 {
69     Q_OBJECT
70     Q_CLASSINFO("D Bus Interface", "org.basket.dbus");
71 public:
72     /// CONSTRUCTOR AND DESTRUCTOR:
73     BNPView(QWidget *parent, const char *name, KXMLGUIClient *aGUIClient,
74             KActionCollection *actionCollection, BasketStatusBar *bar);
75     ~BNPView();
76     /// MANAGE CONFIGURATION EVENTS!:
77     void setTreePlacement(bool onLeft);
78     void relayoutAllBaskets();
79     void recomputeAllStyles();
80     void removedStates(const QList<State*> &deletedStates);
81     void linkLookChanged();
82     void filterPlacementChanged(bool onTop);
83     /// MANAGE BASKETS:
84     BasketListViewItem* listViewItemForBasket(BasketScene *basket);
85     BasketScene* currentBasket();
86     BasketScene* parentBasketOf(BasketScene *basket);
87     void setCurrentBasket(BasketScene *basket);
88     void setCurrentBasketInHistory(BasketScene *basket);
89     void removeBasket(BasketScene *basket);
90     /// For NewBasketDialog (and later some other classes):
91     int topLevelItemCount();
92     ///
93     BasketListViewItem* topLevelItem(int i);
94     int basketCount(QTreeWidgetItem *parent = 0);
95     bool canFold();
96     bool canExpand();
97     void enableActions();
98 
99 private:
100     //! Create <basket> element with <properties>
101     void writeBasketElement(QTreeWidgetItem *item, QXmlStreamWriter &steam);
102 public slots:
103     void countsChanged(BasketScene *basket);
104     void notesStateChanged();
105     bool convertTexts();
106 
107     void updateBasketListViewItem(BasketScene *basket);
108     void save();
109     void save(QTreeWidget* listView, QTreeWidgetItem *firstItem, QXmlStreamWriter &stream);
110     void saveSubHierarchy(QTreeWidgetItem *item, QXmlStreamWriter &stream, bool recursive);
111     void load();
112     void load(QTreeWidgetItem *item, const QDomElement &baskets);
113     void loadNewBasket(const QString &folderName, const QDomElement &properties, BasketScene *parent);
114     void goToPreviousBasket();
115     void goToNextBasket();
116     void foldBasket();
117     void expandBasket();
118     void closeAllEditors();
119     ///
120     void toggleFilterAllBaskets(bool doFilter);
121     void newFilter();
122     void newFilterFromFilterBar();
123     bool isFilteringAllBaskets();
124     // From main window
125     void importKNotes();
126     void importKJots();
127     void importKnowIt();
128     void importTuxCards();
129     void importStickyNotes();
130     void importTomboy();
131     void importJreepadFile();
132     void importTextFile();
133     void backupRestore();
134     void checkCleanup();
135 
136     /** Note */
137     void activatedTagShortcut();
138     void exportToHTML();
139     void editNote();
140     void cutNote();
141     void copyNote();
142     void delNote();
143     void openNote();
144     void openNoteWith();
145     void saveNoteAs();
146     void noteGroup();
147     void noteUngroup();
148     void moveOnTop();
149     void moveOnBottom();
150     void moveNoteUp();
151     void moveNoteDown();
152     void slotSelectAll();
153     void slotUnselectAll();
154     void slotInvertSelection();
155     void slotResetFilter();
156 
157     void slotColorFromScreen(bool global = false);
158     void slotColorFromScreenGlobal();
159     void colorPicked(const QColor &color);
160     void colorPickingCanceled();
161     void slotConvertTexts();
162 
163     /** Global shortcuts */
164     void addNoteText();
165     void addNoteHtml();
166     void addNoteImage();
167     void addNoteLink();
168     void addNoteCrossReference();
169     void addNoteColor();
170     /** Passive Popups for Global Actions */
171     void showPassiveDropped(const QString &title);
172     void showPassiveDroppedDelayed(); // Do showPassiveDropped(), but delayed
173     void showPassiveContent(bool forceShow = false);
174     void showPassiveContentForced();
175     void showPassiveImpossible(const QString &message);
176     void showPassiveLoading(BasketScene *basket);
177     // For GUI :
178     void setFiltering(bool filtering);
179     /** Edit */
180     void undo();
181     void redo();
182     void globalPasteInCurrentBasket();
183     void pasteInCurrentBasket();
184     void pasteSelInCurrentBasket();
185     void pasteToBasket(int index, QClipboard::Mode mode = QClipboard::Clipboard);
186     void showHideFilterBar(bool show, bool switchFocus = true);
187     /** Insert **/
188     void insertEmpty(int type);
189     void insertWizard(int type);
190     void grabScreenshot(bool global = false);
191     void grabScreenshotGlobal();
192     void screenshotGrabbed(const QPixmap &pixmap);
193     /** BasketScene */
194     void askNewBasket();
195     void askNewBasket(BasketScene *parent, BasketScene *pickProperties);
196     void askNewSubBasket();
197     void askNewSiblingBasket();
198     void aboutToHideNewBasketPopup();
199     void setNewBasketPopup();
200     void cancelNewBasketPopup();
201     void propBasket();
202     void delBasket();
203     void doBasketDeletion(BasketScene *basket);
204     void password();
205     void saveAsArchive();
206     void openArchive();
207     void delayedOpenArchive();
208     void delayedOpenBasket();
209     void lockBasket();
210     void hideOnEscape();
211 
212     void changedSelectedNotes();
213     void timeoutTryHide();
214     void timeoutHide();
215 
216     void loadCrossReference(QString link);
217     QString folderFromBasketNameLink(QStringList pages, QTreeWidgetItem *parent = 0);
218 
219     void sortChildrenAsc();
220     void sortChildrenDesc();
221     void sortSiblingsAsc();
222     void sortSiblingsDesc();
223 
224 public:
225     static QString s_fileToOpen;
226     static QString s_basketToOpen;
227 
228 public slots:
229     void addWelcomeBaskets();
230 private slots:
231     void updateNotesActions();
232     void slotBasketChanged();
233     void canUndoRedoChanged();
234     void currentBasketChanged();
235     void isLockedChanged();
236     void lateInit();
237     void onFirstShow();
238 
239 public:
240     QAction *m_actEditNote;
241     QAction *m_actOpenNote;
242     QAction *m_actPaste;
243     QAction *m_actGrabScreenshot;
244     QAction *m_actColorPicker;
245     QAction *m_actLockBasket;
246     QAction *m_actPassBasket;
247     QAction *actNewBasket;
248     QAction *actNewSubBasket;
249     QAction *actNewSiblingBasket;
250     QAction *m_actHideWindow;
251     QAction *m_actExportToHtml;
252     QAction *m_actPropBasket;
253     QAction *m_actSortChildrenAsc;
254     QAction *m_actSortChildrenDesc;
255     QAction *m_actSortSiblingsAsc;
256     QAction *m_actSortSiblingsDesc;
257     QAction *m_actDelBasket;
258     KToggleAction *m_actFilterAllBaskets;
259 
260 private:
261     // Basket actions:
262     QAction *m_actSaveAsArchive;
263     QAction *m_actOpenArchive;
264     // Notes actions :
265     QAction *m_actOpenNoteWith;
266     QAction *m_actSaveNoteAs;
267     QAction *m_actGroup;
268     QAction *m_actUngroup;
269     QAction *m_actMoveOnTop;
270     QAction *m_actMoveNoteUp;
271     QAction *m_actMoveNoteDown;
272     QAction *m_actMoveOnBottom;
273     // Edit actions :
274     QAction *m_actUndo;
275     QAction *m_actRedo;
276     QAction *m_actCutNote;
277     QAction *m_actCopyNote;
278     QAction *m_actDelNote;
279     QAction *m_actSelectAll;
280     QAction *m_actUnselectAll;
281     QAction *m_actInvertSelection;
282     // Insert actions :
283 //      QAction *m_actInsertText;
284     QAction *m_actInsertHtml;
285     QAction *m_actInsertLink;
286     QAction *m_actInsertCrossReference;
287     QAction *m_actInsertImage;
288     QAction *m_actInsertColor;
289     QAction *m_actImportKMenu;
290     QAction *m_actInsertLauncher;
291     QAction *m_actImportIcon;
292     QAction *m_actLoadFile;
293     QList<QAction *> m_insertActions;
294     // Basket actions :
295     KToggleAction *m_actShowFilter;
296     QAction *m_actResetFilter;
297     // Go actions :
298     QAction *m_actPreviousBasket;
299     QAction *m_actNextBasket;
300     QAction *m_actFoldBasket;
301     QAction *m_actExpandBasket;
302 //      QAction *m_convertTexts; // FOR_BETA_PURPOSE
303 
304     void setupActions();
305     void setupGlobalShortcuts();
306     DecoratedBasket* currentDecoratedBasket();
307 
308 public:
309     BasketScene* loadBasket(const QString &folderName); // Public only for class Archive
310     BasketListViewItem* appendBasket(BasketScene *basket, QTreeWidgetItem *parentItem); // Public only for class Archive
311 
312     BasketScene* basketForFolderName(const QString &folderName);
313     Note* noteForFileName(const QString &fileName, BasketScene &basket, Note* note = 0);
314     QMenu* popupMenu(const QString &menuName);
315     bool isPart();
316     bool isMainWindowActive();
317     void showMainWindow();
318 
319     // TODO: dcop calls -- dbus these
320 public Q_SLOTS:
321     Q_SCRIPTABLE void newBasket();
322     Q_SCRIPTABLE void handleCommandLine();
323     Q_SCRIPTABLE void reloadBasket(const QString &folderName);
324     Q_SCRIPTABLE bool createNoteHtml(const QString content, const QString basket);
325     Q_SCRIPTABLE QStringList listBaskets();
326     Q_SCRIPTABLE bool createNoteFromFile(const QString url, const QString basket);
327     Q_SCRIPTABLE bool changeNoteHtml(const QString content, const QString basket, const QString noteName);
328 
329 public slots:
330     void setWindowTitle(QString s);
331     void updateStatusBarHint();
332     void setSelectionStatus(QString s);
333     void setLockStatus(bool isLocked);
334     void postStatusbarMessage(const QString&);
335     void setStatusBarHint(const QString&);
336     void setUnsavedStatus(bool isUnsaved);
337     void setActive(bool active = true);
actionCollection()338     KActionCollection *actionCollection() {
339         return m_actionCollection;
340     };
341 
342     void populateTagsMenu();
343     void populateTagsMenu(QMenu &menu, Note *referenceNote);
344     void connectTagsMenu();
345     void disconnectTagsMenu();
346     void disconnectTagsMenuDelayed();
347 protected:
348     void showEvent(QShowEvent*);
349     void hideEvent(QHideEvent*);
350 private:
351     QMenu *m_lastOpenedTagsMenu;
352 
353 private slots:
354     void slotPressed(QTreeWidgetItem *item, int column);
355     void needSave(QTreeWidgetItem*);
356     void slotContextMenu(const QPoint &pos);
357     void slotShowProperties(QTreeWidgetItem *item);
358     void initialize();
359 
360 signals:
361     void basketChanged();
362     void setWindowCaption(const QString &s);
363     void showPart();
364 
365 protected:
366     void enterEvent(QEvent*);
367     void leaveEvent(QEvent*);
368 
369 protected:
370     void hideMainWindow();
371 
372 private:
373     BasketTreeListView *m_tree;
374     QStackedWidget *m_stack;
375     bool          m_loading;
376     bool          m_newBasketPopup;
377     bool          m_firstShow;
378     DesktopColorPicker *m_colorPicker;
379     bool                m_colorPickWasShown;
380     bool                m_colorPickWasGlobal;
381     RegionGrabber      *m_regionGrabber;
382     QString m_passiveDroppedTitle;
383     NoteSelection *m_passiveDroppedSelection;
384     static const int c_delayTooltipTime;
385     KActionCollection *m_actionCollection;
386     KXMLGUIClient *m_guiClient;
387     BasketStatusBar *m_statusbar;
388     QTimer             *m_tryHideTimer;
389     QTimer             *m_hideTimer;
390 
391     QUndoStack *m_history;
392     KMainWindow *m_HiddenMainWindow;
393 };
394 
395 #endif // BNPVIEW_H
396