summaryrefslogtreecommitdiffstats
path: root/kopete/kopete/chatwindow/kopetechatwindowstylemanager.h
blob: 7c9a181ff8617420ae367eb8af5c834675ff27a9 (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
145
146
147
148
 /*
    kopetechatwindowstylemanager.h - Manager all chat window styles

    Copyright (c) 2005      by Michaël Larouche     <michael.larouche@kdemail.net>

    Kopete    (c) 2002-2005 by the Kopete developers <kopete-devel@kde.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 KOPETECHATWINDOWSTYLEMANAGER_H
#define KOPETECHATWINDOWSTYLEMANAGER_H

#include <tqobject.h>
#include <tqmap.h>
#include <tdefileitem.h>
#include <kopete_export.h>

class ChatWindowStyle;
/**
 * Sigleton class that handle Chat Window styles. 
 * It use style absolute path to avoid unexpected behavior that could happen when using style name.
 *
 * It can install, delete styles. The styles are managed in a pool, they are only retrieved on demand.
 *
 * Use getStyleFromPool to retrieve a ChatWindowStyle instance. Do not delete the returned instance, it
 * is handled by this class.
 *
 * When called the first time, it list all the available styles in $KDEDATADIR/kopete/styles and
 * KDirWatch (via KDirLister) watch for new styles. 
 *
 * If you want to keep a trace of avaiable styles, connect to loadStylesFinished() signal. 
 * It is called when KDirLister finish a job(ex: on new directory).
 *
 * @author Michaël Larouche <michael.larouche@kdemail.net>
 */
class KOPETE_EXPORT ChatWindowStyleManager : public TQObject
{
	Q_OBJECT
  
public:
	/**
	 * StyleList typedef (a TQMap)
	 * key = Name of the style (currently the directory name)
	 * value = Path to the style
	 */
	typedef TQMap<TQString, TQString> StyleList;

	/**
	 * The StyleInstallStatus enum. It gives better return value for installStyle().
	 * - StyleInstallOk : The install went fine.
	 * - StyleNotValid : The archive didn't contain a valid Chat Window style.
	 * - StyleNoDirectoryValid : It didn't find a suitable directory to install the theme.
	 * - StyleCannotOpen : The archive couldn't be openned.
	 * - StyleUnknow : Unknow error.
	 */
	enum StyleInstallStatus { StyleInstallOk = 0, StyleNotValid, StyleNoDirectoryValid, StyleCannotOpen, StyleUnknow };

	/**
	 * Destructor.
	 */
	~ChatWindowStyleManager();

	/**
	 * Singleton access to this class.
	 * @return the single instance of this class.
	 */
	static ChatWindowStyleManager *self();

	/**
	 * List all availables styles.
	 * Init KDirLister and thus KDirWatch that watch for new styles.
	 */
	void loadStyles();

	/**
	 * Get all available styles.
	 */
	StyleList getAvailableStyles();

public slots:
	/**
	 * Install a new style into user style directory
	 * Note that you must pass a path to a archive.
	 *
	 * @param styleBundlePath Path to the container file to install.
	 * @return A status code from StyleInstallStatus enum.
	 */
	int installStyle(const TQString &styleBundlePath);

	/**
	 * Remove a style from user style directory
	 *
	 * @param stylePath the path of the style to remove.
	 * @return true if the deletion went without problems.
	 */
	bool removeStyle(const TQString &stylePath);
	
	/**
	 * Get a instance of a ChatWindowStyle from the pool.
	 * If they are no instance for the specified style, it gets created.
	 * DO NOT DELETE the resulting pointer, it is handled by this class.
	 *
	 * @param stylePath Path for the specified style. Name can be ambigous.
	 * @return the instance of ChatWindow for the specified style. DO NOT DELETE IT.
	 */
	ChatWindowStyle *getStyleFromPool(const TQString &stylePath);

signals:
	/**
	 * This signal is emitted when all styles finished to list.
	 * Used to inform and/or update GUI.
	 */
	void loadStylesFinished();

private slots:
	/**
	 * KDirLister found new files.
	 * @param dirList new files found.
	 */
	void slotNewStyles(const KFileItemList &dirList);
	/**
	 * KDirLister finished a job.
	 * Emit loadStylesFinished() if they are no directory left in the stack.
	 */
	void slotDirectoryFinished();

private:
	/**
	 * Private constructor(it's a singleton class)
	 * Call loadStyles() to list all avaiable styles.
	 */
	ChatWindowStyleManager(TQObject *parent = 0, const char *name = 0);

	static ChatWindowStyleManager *s_self;

	class Private;
	Private *d;
};

#endif