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 149 150 151 152 153 154 155
|
/*
kopetechat-window-style-manager.h - Manager all chat window styles
Copyright (c) 2005 by Michaël Larouche <larouche@kde.org>
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 CHATWINDOWSTYLEMANAGER_H
#define CHATWINDOWSTYLEMANAGER_H
#include <QtCore/QObject>
#include <QtCore/QHash>
#include <KFileItem>
#include "ktpchat_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 <larouche@kde.org>
*/
class KDE_TELEPATHY_CHAT_EXPORT ChatWindowStyleManager : public QObject
{
Q_OBJECT
public:
/**
* 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.
*/
virtual ~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.
*/
QMap<QString, QString> getAvailableStyles() const;
public Q_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 QString &styleBundlePath);
/**
* Remove a style from user style directory
*
* @param styleName the name of the style to remove.
* @return true if the deletion went without problems.
*/
bool removeStyle(const QString &styleName);
/**
* 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 styleName name for the specified style. If style with this name
* exists in both global and user directories, the user one will be returned
* @return the instance of ChatWindow for the specified style or 0 if valid style
* wasn't found. DO NOT DELETE IT.
*/
ChatWindowStyle* getStyleFromPool(const QString &styleName);
/**
* Get a instance of a ChatWindowStyle from the pool.
* If they are no instance for the specified style, it gets created.
* If the style doesn't exists or is invalid default style is returned or 0.
* DO NOT DELETE the resulting pointer, it is handled by this class.
*
* @param styleName name for the specified style. If style with this name
* exists in both global and user directories, the user one will be returned
* @return the instance of ChatWindow for the specified style or 0 if valid style
* wasn't found. DO NOT DELETE IT.
*/
ChatWindowStyle* getValidStyleFromPool(const QString &styleName);
Q_SIGNALS:
/**
* This signal is emitted when all styles finished to list.
* Used to inform and/or update GUI.
*/
void loadStylesFinished();
private Q_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(QObject *parent = 0);
class Private;
Private * const d;
};
#endif
|