]> git.sven.stormbind.net Git - sven/vym.git/blob - vymmodel.h
1c85b934d0aa44fd9758531afefd59eb379a37a0
[sven/vym.git] / vymmodel.h
1 #ifndef VYMMODEL_H
2 #define VYMMODEL_H
3
4 #include <QtNetwork>
5
6 #include <QPointF>
7 #include <QTextCursor>
8
9 #if defined(VYM_DBUS)
10 #include "adaptormodel.h"
11 #endif
12
13 #include "file.h"
14 #include "branchitem.h"
15 #include "imageitem.h"
16 #include "mapeditor.h"
17 #include "parser.h"
18 #include "treeitem.h"
19 #include "treemodel.h"
20 #include "vymlock.h"
21
22 class AttributeItem;
23 class BranchItem;
24 class FindResultModel;
25 class Link;
26 class MapEditor;
27 class SlideItem;
28 class SlideModel;
29 class Task;
30 class XLinkItem;
31 class VymView;
32
33 class QGraphicsScene;
34
35 typedef QMap<uint,QString> ItemList ;
36
37 class VymModel :  public TreeModel {        
38     Q_OBJECT
39     Q_CLASSINFO("D-Bus Interface", "org.insilmaril.vym.VymModel-h")
40
41 ////////////////////////////////////////////
42 // General housekeeping
43 ////////////////////////////////////////////
44 private:
45     QString version;    //!< version string saved in vym file
46     QString title;
47     QString author;
48     QString comment;
49     QDate date;
50
51     static uint idLast;     //! the last used unique ID
52     uint modelID;
53
54 public:
55     VymModel();
56     ~VymModel ();
57     void clear();
58     void init();
59     void makeTmpDirectories();      //!< create temporary directories e.g. for history
60
61     MapEditor* getMapEditor();          
62     uint getModelID();                  //! Return unique ID of model
63
64     void setView (VymView*);        //! Set vymView for resizing editors after load
65 private:
66     VymView *vymView;
67
68 public:
69     bool isRepositionBlocked();     //!< While load or undo there is no need to update graphicsview
70     void updateActions();           //!< Update buttons in mainwindow
71
72
73 ////////////////////////////////////////////
74 // Load/save 
75 ////////////////////////////////////////////
76 private:
77
78     bool zipped;                // should map be zipped
79     static  int mapNum;         // unique number for model used in save/undo
80     FileType fileType;          // type of file, e.g. vym, freemind...
81     QString fileName;           // short name of file (for tab)
82                                 // example.vym
83
84     QString filePath;           // path to file which will be saved
85                                 // /home/tux/example.vym
86
87     QString fileDir;            // dir where file is saved
88                                 // /home/tux/
89
90     QString destPath;           // path to .vym file (needed for vymlinks)
91                                 // /home/tux/example.vym
92
93     QString mapName;            // fileName without ".vym"
94                                 // example
95
96     QString tmpMapDir;          // tmp directory with undo history
97
98     QTimer *autosaveTimer;
99     QTimer *fileChangedTimer;
100     QDateTime fileChangedTime;
101
102 public:
103     /*! This function saves all information of the map to disc.
104         saveToDir also calls the functions for all BranchObj and other objects in the map.
105         The structure of the map itself is returned as QString and passed back to Main, 
106         where saveToDir is called initially
107     */  
108     QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, TreeItem *saveSel);
109
110     /*! Save all data in tree*/
111     QString saveTreeToDir (const QString&,const QString&,const QPointF&,QList <Link*> &tmpLinks);// Save data recursivly to tempdir
112
113
114     /*! \brief Sets filepath, filename and mapname
115
116          If the filepath is "/home/tux/map.xml", then the filename will be set
117          to map.xml. The destname is needed for vymLinks, pointing to another map. 
118          The destname holds the real name of the file, after it has been compressed, e.g. "map.vym"
119     */   
120
121
122     /*! \brief Set File path
123
124          The destname is needed to construct the references between maps
125     */   
126     void setFilePath (QString filepath,QString destname);   
127     void setFilePath (QString); //!< Overloaded for convenience
128     QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml"
129     QString getFileDir ();  //!< e.g. "/home/tux"
130     QString getFileName (); //!< e.g. "map.xml"
131     QString getMapName ();  //!< e.g. "map"
132     QString getDestPath (); //!< e.g. "/home/tux/map.vym"
133
134     bool parseVymText(const QString &s);
135
136     /*! \brief Load map
137
138         The data is read from file. Depending on LoadMode the current
139         selection gets replaced by data or the data is appended.
140     */  
141     File::ErrorCode loadMap  (
142         QString,                        //!< Path
143         const LoadMode &lmode=NewMap,   //!< New map, replace or add to selection
144         const FileType &ftype=VymMap,   //!< VymMap or FreeMind
145         const int &contentFilter=0x0000,//!< For undo types of content can be filterd
146         int pos=-1                      //!< Optionally tell position where to add data
147     );  
148
149 public:
150     /*! \brief Save the map to file */
151     File::ErrorCode save(const SaveMode &);     
152
153 public: 
154     void loadImage (BranchItem *dst=NULL, const QString &fn="");
155     void saveImage (ImageItem *ii=NULL, QString format="", QString fn="");
156
157 private:    
158     void importDirInt(BranchItem *,QDir);
159     void importDirInt(const QString&);
160 public: 
161     void importDir();
162
163     bool tryVymLock();
164     bool renameMap( const QString &newPath); //! Rename map and change lockfile
165     void setReadOnly( bool b );
166     bool isReadOnly();
167
168 private:
169     VymLock  vymLock;       //! Handle lockfiles and related information
170     bool readonly;          //! if map is locked, it can be opened readonly
171
172 private slots:
173     void autosave ();
174     void fileChanged();
175
176 ////////////////////////////////////////////
177 // history (undo/redo)
178 ////////////////////////////////////////////
179 private:
180     bool mapDefault;            //!< Flag if map is untouched
181     bool mapChanged;            //!< Flag if undo is possible
182     bool mapUnsaved;            //!< Flag if map should be saved
183
184     QString histPath;           //!< Path to history file
185     SimpleSettings undoSet;     //!< undo/redo commands, saved in histPath
186     int stepsTotal;             //!< total number of steps (undos+redos)
187     int curStep;                //!< Current step in history (ring buffer)
188     int curClipboard;           //!< number of history step, which is the current clipboard
189     int redosAvail;             //!< Available number of redo steps
190     int undosAvail;             //!< Available number of undo steps
191     bool blockReposition;       //!< block while load or undo
192     bool blockSaveState;        //!< block while load or undo
193 public:
194     bool isDefault();           //!< true, if map is still the empty default map
195     void makeDefault();         //!< Reset changelog, declare this as default map
196     bool hasChanged()   ;       //!< true, if something has changed and is not saved yet
197     void setChanged();          //!< called from TextEditor via LinkableMapObj
198
199     /*! \brief Get name of object
200       
201       Returns heading of a branch or name of an object for use in comment
202       of undo/redo history
203     */ 
204     QString getObjectName(LinkableMapObj*); 
205     QString getObjectName(TreeItem*);   
206
207     void redo();                        //!< Redo last action
208     bool isRedoAvailable();             //!< True, if redo is available
209     void undo();                        //!< Undo last action
210     bool isUndoAvailable();             //!< True, if undo is available
211     void gotoHistoryStep (int);         //!< Goto a specifig step in history
212
213
214     QString getHistoryPath();           //!< Path to directory containing the history
215     void resetHistory();                //!< Initialize history
216
217     /*! \brief Save the current changes in map 
218
219         Two commands and selections are saved:
220
221             - undocommand and undoselection to undo the change
222             - redocommand and redoselection to redo the action after an undo
223
224         Additionally a comment is logged. 
225
226     */  
227     void saveState(
228         const SaveMode& savemode, 
229         const QString &undoSelection, 
230         const QString &undoCommand, 
231         const QString &redoSelection, 
232         const QString &redoCommand, 
233         const QString &comment, 
234         TreeItem *saveSelection,
235         QString dataXML="");
236
237     /*! Overloaded for convenience */
238     void saveStateChangingPart(
239         TreeItem *undoSelection, 
240         TreeItem* redoSelection, 
241         const QString &redoCommand, 
242         const QString &comment);
243
244     /*! Overloaded for convenience */
245     void saveStateRemovingPart(
246         TreeItem *redoSelection, 
247         const QString &comment);
248
249     /*! Overloaded for convenience */
250     void saveState(
251         TreeItem *undoSelection, 
252         const QString &undoCommand, 
253         TreeItem *redoSelection, 
254         const QString &redoCommand, 
255         const QString &comment); 
256
257     /*! Overloaded for convenience */
258     void saveState(
259         const QString &undoSelection, 
260         const QString &undoCommand, 
261         const QString &redoSelection, 
262         const QString &redoCommand, 
263         const QString &comment) ;
264
265     /*! Overloaded for convenience */
266     void saveState(
267         const QString &undoCommand, 
268         const QString &redoCommand, 
269         const QString &comment) ;
270
271     /*! Save a change in string and merge
272         minor sequential  changes  */
273     void saveStateMinimal(
274         TreeItem *undoSelection, 
275         const QString &undoCommand, 
276         TreeItem *redoSelection, 
277         const QString &redoCommand, 
278         const QString &comment); 
279         
280     /*! Save state before loading a map */
281     void saveStateBeforeLoad (
282         LoadMode lmode,
283         const QString &fname);
284
285 ////////////////////////////////////////////
286 // unsorted so far
287 ////////////////////////////////////////////
288 public:
289     QGraphicsScene *getScene();
290
291     TreeItem* findBySelectString (QString s);       
292     TreeItem* findID   (const uint &i);     // find MapObj by unique ID
293     TreeItem* findUuid (const QUuid &i);    // find MapObj by unique ID
294
295
296 ////////////////////////////////////////////
297 // Interface 
298 ////////////////////////////////////////////
299 public:
300     void setVersion(const  QString &);
301     QString getVersion();
302     void setTitle  (const QString &);
303     QString getTitle ();
304     void setAuthor  (const QString &);
305     QString getAuthor ();
306     void setComment (const QString &);
307     QString getComment ();
308     QString getDate();
309     int branchCount();
310
311     void setSortFilter (const QString &);
312     QString getSortFilter ();
313 protected:  
314     QString sortFilter;
315 signals:
316     void sortFilterChanged (QString );      //!< Notify editors of new filter
317
318 public:
319     void setHeading(const VymText &vt, BranchItem *bi=NULL);        //!< Set heading of item
320     void setHeadingPlainText(const QString &s, BranchItem *bi=NULL);    //!< Set heading of item
321     Heading getHeading();                       //!< Get heading of item
322     void setNote(const VymNote &vn);    //!< Set note text
323     VymNote getNote();                          //!< Get note text
324     bool hasRichTextNote();             //!< Check type of vymText used
325     void loadNote (const QString &fn);  //!< Load note from file
326     void saveNote (const QString &fn);  //!< Save note to file
327
328 private:
329     BranchItem* findCurrent;                // next object in find process
330     BranchItem* findPrevious;               // next object in find process
331     bool EOFind;                            // true, if search failed
332
333 public:
334     void findDuplicateURLs();               // find duplicate URLs, testing only so far
335     bool findAll (FindResultModel*, QString s, Qt::CaseSensitivity cs=Qt::CaseInsensitive);     // Search all objects at once, also notes
336     BranchItem* findText(QString s,Qt::CaseSensitivity cs); // Find object, also in note
337     void findReset();                       // Reset Search
338 private:    
339     QString findString;
340
341 public:
342     void setURL(QString url);
343     QString getURL();                       // returns URL of selection or ""
344     QStringList getURLs(bool ignoreScrolled=true);  // returns URLs of subtree
345
346
347     void setFrameType(const FrameObj::FrameType &);
348     void setFrameType(const QString &);
349     void toggleFrameIncludeChildren ();
350     void setFrameIncludeChildren (bool);
351     void setFramePenColor (const QColor &);
352     void setFrameBrushColor (const QColor &);
353     void setFramePadding (const int &);
354     void setFrameBorderWidth (const int &);
355     void setIncludeImagesVer(bool);
356     void setIncludeImagesHor(bool);
357     void setChildrenLayout(BranchItem::LayoutHint layoutHint);
358     void setHideLinkUnselected (bool);
359
360     /*! Should object be hidden in exports (clouded)? */
361     void setHideExport(bool, TreeItem* ti=NULL);                
362
363     /*! Should object be hidden in exports (clouded)? */
364     void toggleHideExport();        
365
366     /*! Toggle task for branch */
367     void toggleTask();      
368
369     /*! Cycle through task states */
370     void cycleTaskStatus(bool reverse=false);       
371
372     /*! Set task to sleep for number of days or until a given date*/
373     bool setTaskSleep(const QString &s);
374     /*! count tasks in this model */
375     int taskCount();
376
377     void addTimestamp();        
378
379     void copy();                        //!< Copy to clipboard
380 public: 
381     void paste();           //!< Paste clipboard to branch and backup
382     void cut();             //!< Cut to clipboard (and copy)
383
384     bool moveUp(BranchItem *bi);    //!< Move branch up without saving state
385     void moveUp();                  //!< Move branch up with saving state
386     bool moveDown(BranchItem *bi);  //!< Move branch down without saving state
387     void moveDown();        //!< Move branch down
388     void detach();                  //!< Detach branch and use as new mapcenter
389     void sortChildren(bool inverse=false);  //!< Sort children lexically
390
391     // The create methods are used to quickly parse a XML file
392     BranchItem* createMapCenter();              //!< Create MapCenter 
393     BranchItem* createBranch(BranchItem *dst);  //!< Create Branch
394     ImageItem* createImage(BranchItem *dst);    //!< Create image
395
396 public: 
397     bool createLink(Link *l);   //!< Create XLink, will create MO automatically if needed 
398     QColor getXLinkColor();
399     int getXLinkWidth();
400     Qt::PenStyle getXLinkPenStyle();
401     QString getXLinkStyleBegin();
402     QString getXLinkStyleEnd();
403
404     AttributeItem* addAttribute();
405     AttributeItem* addAttribute(BranchItem *dst, AttributeItem* );
406
407     /*! \brief Add new mapcenter
408
409         Disclaimer: Still experimental, not fully supported yet.
410     */  
411     BranchItem* addMapCenter(bool saveStateFlag=true);
412 private:    
413     BranchItem* addMapCenter(QPointF absPos);
414
415     /*! \brief Add new branch
416
417         Depending on num the new branch is created
418
419         -3 above selection as child of selections parent
420         -2 as child of selection
421         -1 below selection as child of selections parent
422         0..n    insert at a specific position in selections parent
423         (needed for free relinking)
424     */  
425
426 private:    
427     BranchItem* addNewBranchInt(BranchItem *dst, int pos);  // pos allows to add above/below selection, or as child  at pos
428 public: 
429     /*! \Add new branch
430         
431     // Depending on pos:
432     // -3       insert in children of parent  above selection 
433     // -2       add branch to selection 
434     // -1       insert in children of parent below selection 
435     // 0..n     insert in children of parent at pos
436     */
437     BranchItem* addNewBranch(BranchItem *bi=NULL, int pos=-2);  
438     BranchItem* addNewBranchBefore();       //!< Insert branch between selection and its parent
439     /*! \brief Relink a branch to a new destination dst 
440         Relinks branch to dst at branch position pos. There is no saveState
441         here, as for example moveUp or moving in MapEditor have
442         different needs to call saveState
443         Returns true if relinking was successful.
444     */  
445     bool relinkBranch (
446         BranchItem* branch, 
447         BranchItem* dst, 
448         int pos =-1, 
449         bool updateSelection=false, 
450         QPointF orgPos=QPointF() 
451     );   
452     bool relinkImage  (ImageItem* image, BranchItem* dst);  
453
454 private:
455     bool cleaningUpLinks;               //!< True while cleaning up to avoid recursion
456 public: 
457    void cleanupItems();         //!< Delete orphaned Items
458     void deleteLater (uint);            //!< Delete later with new beginRemoveRow
459     void deleteSelection();             //!< Delete selection
460     void deleteKeepChildren(bool saveStateFlag=true);   //!< remove branch, but keep children
461 public: 
462     void deleteChildren();              //!< keep branch, but remove children
463
464     TreeItem* deleteItem(TreeItem*);    //!< Delete item and return parent (if parent!= rootItem)
465     void deleteLink (Link*);            //!< Remove Link and related LinkItems in TreeModel
466     void clearItem (TreeItem* ti);      //!< Remove all children of TreeItem ti
467     bool scrollBranch(BranchItem *);
468     bool unscrollBranch(BranchItem *);
469     void toggleScroll();
470     void unscrollChildren();
471     void setScale (qreal,qreal);
472     void growSelectionSize();
473     void shrinkSelectionSize();
474     void resetSelectionSize();
475     void emitExpandAll();
476     void emitExpandOneLevel();
477     void emitCollapseOneLevel();
478     void emitCollapseUnselected();
479 signals:    
480     void expandAll();
481     void expandOneLevel();
482     void collapseOneLevel();
483     void collapseUnselected();
484
485 public: 
486     void toggleTarget();
487     ItemList getTargets();
488
489     void toggleStandardFlag (const QString &name, FlagRow *master=NULL);
490     void addFloatImage(const QImage &img);
491
492     void colorBranch(QColor);
493     void colorSubtree(QColor,BranchItem *bi=NULL);
494     QColor getCurrentHeadingColor();
495
496
497     void note2URLs();                       // get URLs from note
498     void editHeading2URL();                 // copy heading to URL
499     void editBugzilla2URL();                // create URL to Bugzilla
500     void getBugzillaData(bool subtree);     // get data from Novell Bugzilla
501     void editFATE2URL();                    // create URL to FATE
502     void setVymLink (const QString &);  // Set vymLink for selection
503     void deleteVymLink();                   // delete link to another map
504     QString getVymLink();                   // return path to map
505     QStringList getVymLinks();              // return paths in subtree
506     void followXLink (int);
507     void editXLink ();
508     void setXLinkColor(const QString &);
509     void setXLinkLineStyle(const QString &);
510     void setXLinkStyleBegin(const QString &);
511     void setXLinkStyleEnd(const QString &);
512     void setXLinkWidth(int);
513
514 ////////////////////////////////////////////
515 // Scripting
516 ////////////////////////////////////////////
517 public: 
518
519     /* \brief Process one command and its parameters */
520     QVariant parseAtom (const QString &atom, bool &noError, QString &errorMsg); 
521
522     /* \brief Runs the script */
523     QVariant execute (const QString &script);
524
525     Parser parser;
526
527 ////////////////////////////////////////////
528 // Exports
529 ////////////////////////////////////////////
530 private:
531     TreeItem::HideTmpMode hidemode; // true while exporting to hide some stuff
532
533 public:
534     /*! Set or unset temporary hiding of objects during export  */
535     void setExportMode (bool);
536
537     /*! Save as image. Returns offset to upper left corner of image */
538     QPointF exportImage (QString fname="",bool askForName=true,QString format="PNG");
539
540     /*! Save as PDF  . Returns offset to upper left corner of image */
541     void exportPDF (QString fname="",bool askForName=true);
542
543     /*! Save as SVG  . Returns offset to upper left corner of image */
544     QPointF exportSVG (QString fname="",bool askForName=true);
545
546     /*! Export as XTML to directory */
547     void exportXML(QString dir="", QString fname="", bool useDialog=true);    
548
549     /*! Export as A&O report text to file */
550     void exportAO (QString fname="",bool askForName=true);  
551
552     /*! Export as ASCII text to file */
553     void exportASCII (bool listTasks = false, const QString &fname = "",bool askForName = true);
554
555     /*! Export as CSV text to file */
556     void exportCSV (const QString &fname="",bool askForName=true);  
557
558     /*! Export as HTML to directory */
559     void exportHTML(const QString &dir="", const QString &fname="", bool useDialog=true);    
560
561     /*! Export as OpenOfficeOrg presentation */
562     void exportImpress (const QString &,const QString &);       
563
564     /*! Returns if Export in recently used format is possible*/
565     bool exportLastAvailable(
566         QString &description, 
567         QString &command, 
568         QString &configFile,
569         QString &path);
570
571     /*! Export in recently used format (saved in map)*/
572     void exportLast();
573
574     /*! Export as LaTeX */
575     void exportLaTeX (const QString& dir="", bool useDialog=true);    
576
577     /*! Export as OrgMode input for emacs*/
578     void exportOrgMode (const QString& fname="", bool useDialog=true);    
579
580 ////////////////////////////////////////////
581 // View related
582 ////////////////////////////////////////////
583 public:
584     void registerEditor (QWidget *);
585     void unregisterEditor (QWidget *);
586
587     void setMapZoomFactor (const double &); 
588     void setMapRotationAngle (const double&);
589     void setMapAnimDuration(const int &d);
590     void setMapAnimCurve(const QEasingCurve &c);
591 private: 
592     double zoomFactor;
593     double rotationAngle;
594     int animDuration;
595     QEasingCurve animCurve;
596
597     bool hasContextPos;                 //!< True, if we have a context pos
598     QPointF contextPos;                 //!< local position during context menu
599 public:
600     void setContextPos (QPointF);       //!< local position during context menu
601     void unsetContextPos ();            //!< forget local position after context menu
602
603     void updateNoteFlag();              //!< Signal origination in TextEditor
604     void reposition();                  //!< Call reposition for all MCOs
605     void setHideTmpMode (TreeItem::HideTmpMode mode);   
606
607     void emitNoteChanged  (TreeItem *ti);
608     void emitDataChanged  (TreeItem *ti);
609     void emitUpdateQueries   ();       //!< tell MainWindow to update find results...
610     void emitUpdateLayout ();
611
612 signals:
613     void updateQueries(VymModel *m);
614     void updateLayout();
615     void noteChanged (QModelIndex ix);
616     void newChildObject(QModelIndex ix);
617
618 private:
619     MapEditor *mapEditor;
620
621     QColor defLinkColor;        // default color for links
622     QPen defXLinkPen;           // default pen for xlinks
623     QString defXLinkStyleBegin; // default style begin
624     QString defXLinkStyleEnd; ; // default style end
625     LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color
626     LinkableMapObj::Style linkstyle;        // default style for links
627     QFont defaultFont;
628
629 public:
630     bool setMapLinkStyle (const QString &); // Set style of link
631     LinkableMapObj::Style getMapLinkStyle ();   // requested in LMO
632     void setMapDefLinkColor(QColor);        // default color of links
633     void setMapLinkColorHintInt();          // color of links
634     void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links
635     void toggleMapLinkColorHint();          // after changing linkStyles
636     void selectMapBackgroundImage();
637     void setMapBackgroundImage(const QString &);
638     void selectMapBackgroundColor();
639     void setMapBackgroundColor(QColor);
640     QColor getMapBackgroundColor();
641
642     QFont getMapDefaultFont();
643     void setMapDefaultFont (const QFont&);
644
645     LinkableMapObj::ColorHint getMapLinkColorHint();
646     QColor getMapDefLinkColor();
647     void setMapDefXLinkPen (const QPen &p);
648     QPen getMapDefXLinkPen();
649
650     void setMapDefXLinkStyleBegin( const QString &s);
651     QString getMapDefXLinkStyleBegin();
652     void setMapDefXLinkStyleEnd  ( const QString &s);
653     QString getMapDefXLinkStyleEnd();
654
655     /*!  Move absolutly to (x,y).  */   
656     void move    (const double &x, const double &y);
657
658     /*!  Move relativly to (x,y).  */   
659     void moveRel (const double &x, const double &y);
660
661 ////////////////////////////////////////////
662 // Animation  **experimental**
663 ////////////////////////////////////////////
664 private:    
665     QTimer *animationTimer;
666     bool animationUse;
667     uint animationTicks;
668     uint animationInterval;
669     int timerId;                // animation timer
670     QList <MapObj*> animObjList;// list with animated objects 
671
672 private slots:
673     void animate();                     //!< Called by timer to animate stuff
674 public:
675     void startAnimation(BranchObj *bo, const QPointF &v);
676     void startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest);
677     void stopAnimation(MapObj *mo);
678     void stopAllAnimation();
679
680 ////////////////////////////////////////////
681 // Network related 
682 ////////////////////////////////////////////
683 public:
684     /*! \brief Networking states
685         
686         In Network modus we want to switch of saveState, autosave, ...
687     */
688     enum NetState {
689         Offline,            //!< Offline
690         Client,             //!< I am the client and connected to server
691         Server              //!< I am the server
692     };
693
694 private:
695     // Network connections **Experimental**
696     NetState netstate;          // offline, client, server
697     QTcpServer *tcpServer;      // Act as server in conference mode (experimental)
698     QList <QTcpSocket*> clientList;     // List of connected clients
699     quint16 sendCounter;        // Increased with every sent command
700
701     QTcpSocket  *clientSocket;  // socket of this client
702     QString server;             // server address of this client
703     int port;                   // server port of this client
704
705 protected:
706     void sendSelection();
707
708 public:
709     void newServer();
710     void connectToServer();
711
712 private slots:  
713     void newClient();
714     void sendData(const QString &s);
715     void readData();
716     void displayNetworkError (QAbstractSocket::SocketError);
717
718 public:
719     void downloadImage (const QUrl &url, BranchItem *bi=NULL);
720
721 ////////////////////////////////////////////
722 // Selection related 
723 ////////////////////////////////////////////
724 private:
725     TreeItem *latestAddedItem;              // latest added object, reset on setChanged()
726     QList <uint> selectionHistory;
727     int currentSelection;
728     bool keepSelectionHistory;                      // If set, selection doesn't change history
729
730 public slots:
731     void updateSelection(QItemSelection ,QItemSelection); // update selection
732
733 public:
734     void setSelectionModel(QItemSelectionModel *);      // Set common selectionModel
735     QItemSelectionModel* getSelectionModel();
736
737     void setSelectionBlocked(bool);
738     bool isSelectionBlocked();
739
740     bool select (const QString &);          //! Select by string
741     bool selectID (const QString &);        //! select by unique ID (QUuid)
742     bool select (LinkableMapObj *lmo);      //! Select by pointer to LMO
743     bool selectToggle (TreeItem *ti);       //! Toggle select state
744     bool select (TreeItem *ti );            //! Select by pointer to TreeItem
745     bool select (const QModelIndex &index); //! Select by ModelIndex
746     void unselectAll ();
747     void unselect (QItemSelection desel);
748     bool reselect();
749     bool canSelectPrevious();
750     bool selectPrevious();
751     bool canSelectNext();
752     bool selectNext();
753     void resetSelectionHistory();
754     void appendSelection();
755
756     void emitShowSelection();               //!< Show selection in all views
757 signals:
758     void showSelection();
759
760 public: 
761     bool selectFirstBranch();
762     bool selectLastBranch();
763     bool selectLastSelectedBranch();
764     bool selectLastImage();
765     bool selectParent();
766
767 public:
768     TreeItem::Type selectionType();
769     LinkableMapObj* getSelectedLMO();
770     BranchObj* getSelectedBranchObj();
771     BranchItem* getSelectedBranch();
772     QList <BranchItem*> getSelectedBranches();
773     ImageItem* getSelectedImage();
774     Task *getSelectedTask();
775     XLinkItem* getSelectedXLinkItem();
776     Link* getSelectedXLink();
777     AttributeItem* getSelectedAttribute();
778     TreeItem* getSelectedItem();
779     QList <TreeItem*> getSelectedItems();
780     QModelIndex getSelectedIndex();
781     QList <uint> getSelectedIDs();
782     bool isSelected(TreeItem*);
783     QString getSelectString ();
784     QString getSelectString (LinkableMapObj *lmo);
785     QString getSelectString (TreeItem *item);
786     QString getSelectString (BranchItem *item);
787     QString getSelectString (const uint &i);
788     
789     
790 signals:
791     void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
792
793 public:
794     void emitSelectionChanged(const QItemSelection &oldsel);
795     void emitSelectionChanged();
796     void selectMapLinkColor();
797     void selectMapSelectionColor();
798 private:    
799     void setSelectionColorInt(QColor);
800     QItemSelectionModel *selModel;
801     QString lastSelectString;
802     bool selectionBlocked;      //! Used to block changes of selection while editing a heading
803
804 public: 
805     void setSelectionColor(QColor);
806     QColor getSelectionColor();
807
808 ////////////////////////////////////////////
809 // Slide related
810 ////////////////////////////////////////////
811 public:
812     SlideModel* getSlideModel();
813     int slideCount();
814     SlideItem* addSlide ();
815     void deleteSlide (SlideItem *si);
816     void deleteSlide (int n);
817     void relinkSlide (SlideItem *si, int pos);
818     void moveSlideUp( int n=-1);
819     void moveSlideDown( int n=-1);
820     SlideItem *findSlideID (uint id);
821 public slots:
822     void updateSlideSelection (QItemSelection ,QItemSelection);
823 private:
824     SlideModel* slideModel;
825     bool blockSlideSelection;
826
827 };
828 #endif