summaryrefslogtreecommitdiffstats
path: root/src/filemetainfo.h
blob: 6fed08b01272f2d9bc624f961f9ac5d10d398b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef FILEMETAINFO_H
#define FILEMETAINFO_H

#include "outputmethoddlg.h"


class TextDocument;
class TextView;
class TDEConfig;
typedef TQValueList<int> IntList;

class MetaInfo
{
	public:
		MetaInfo();
		
		/**
		 * Returns true if all the data stored is default; and therefore does
		 * not need saving.
		 */
		bool hasDefaultData() const;
		/**
		 * Writes to the given config the data stored in here. Does not set the
		 * group.
		 */
		void save( TDEConfig * conf );
		/**
		 * Reads in the data from the config. Does not set the group.
		 */
		void load( TDEConfig * conf );
		
		IntList bookmarks() const { return m_bookmarks; }
		void setBookmarks( IntList bookmarks ) { m_bookmarks = bookmarks; }
		
		IntList breakpoints() const { return m_breakpoints; }
		void setBreakpoints( IntList breakpoints ) { m_breakpoints = breakpoints; }
		
		OutputMethodInfo & outputMethodInfo() { return m_outputMethodInfo; }
		void setOutputMethodInfo( OutputMethodInfo info ) { m_outputMethodInfo = info; }
		
		unsigned cursorLine() const { return m_cursorLine; }
		void setCursorLine( unsigned line ) { m_cursorLine = line; }
		
		unsigned cursorColumn() const { return m_cursorColumn; }
		void setCursorColumn( unsigned column ) { m_cursorColumn = column; }
		
	protected:
		/**
		 * Convert the id (e.g. "Direct") to a method, used when reading in the
		 * config file.
		 */
		OutputMethodInfo::Method::Type toMethod( const TQString & id );
		/**
		 * Conver the method (e.g. OutputMethodInfo::Method::Direct) to an id
		 * that can be saved in the config file.
		 */
		TQString toID( OutputMethodInfo::Method::Type method );
		
		IntList m_bookmarks;
		IntList m_breakpoints;
		OutputMethodInfo m_outputMethodInfo;
		unsigned m_cursorLine;
		unsigned m_cursorColumn;
};
typedef TQMap<KURL,MetaInfo> MetaInfoMap;

/**
Looks after per-file metainfo; e.g. bookmarks, breakpoints, compiling options, etc

@author David Saxton
*/
class FileMetaInfo : public TQObject
{
	Q_OBJECT
  
	public:
		~FileMetaInfo();
	
		/**
		 * Initialize the TextDocument with the appropriate stored metainfo - e.g.
		 * setting the appopriate bookmarks, etc
		 */
		void initializeFromMetaInfo( const KURL & url, TextDocument * textDocument );
		/**
		 * Initialize the TextView with the appropriate stored metainfo - e.g.
		 * setting the appopriate cursor position, etc.
		 */
		void initializeFromMetaInfo( const KURL & url, TextView * textView );
		/**
		 * Initialize the OutputMethodDlg with the options the user had selected
		 * for the last time it was used for the given url.
		 */
		void initializeFromMetaInfo( const KURL & url, OutputMethodDlg * outputMethodDlg );
		/**
		 * Get the bookmarks, etc from the given TextDocument, and save them
		 */
		void grabMetaInfo( const KURL & url, TextDocument * textDocument );
		/**
		 * Get the cursor position, etc from the given TextView, and save them.
		 */
		void grabMetaInfo( const KURL & url, TextView * textView );
		/**
		 * Get the output method et al from the given OutputMethodDlg, and save
		 * them.
		 */
		void grabMetaInfo( const KURL & url, OutputMethodDlg * outputMethodDlg );
		/**
		 * Save all metainfo to disk.
		 */
		void saveAllMetaInfo();

	protected:
		/**
		 * Load all metainfo from disk (combining that read in with those already
		 * loaded)
		 */
		void loadAllMetaInfo();
	
		TDEConfig *m_metaInfoConfig;
	
	private:
		FileMetaInfo();
		friend inline FileMetaInfo* fileMetaInfo();
	
		MetaInfoMap m_metaInfoMap;
};

inline FileMetaInfo* fileMetaInfo()
{
	static FileMetaInfo *fmi = new FileMetaInfo();
	return fmi;
}

#endif