summaryrefslogtreecommitdiffabout
path: root/microkde/kresources/factory.h
blob: a265bc8a84077c4a0734c286425df5717adaef4b (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
/*
    This file is part of libkresources.

    Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
    Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef KRESOURCES_FACTORY_H
#define KRESOURCES_FACTORY_H

#include <qdict.h>
#include <qstring.h>

#include <kconfig.h>


#include "resource.h"

namespace KRES {

//US
struct PluginInfo
{
  QString library;
  QString nameLabel;
  QString descriptionLabel;
};


/**
 * Class for loading resource plugins.
 * Do not use this class directly. Use ResourceManager instead
 *
 * Example:
 *
 * <pre>
 * KABC::Factory<Calendar> *factory = KABC::Factory<Calendar>::self();
 *
 * QStringList list = factory->resources();
 * QStringList::Iterator it;
 * for ( it = list.begin(); it != list.end(); ++it ) {
 *   Resource<Calendar> *resource = factory->resource( (*it),
 *        KABC::StdAddressBook::self(), 0 );
 *   // do something with resource
 * }
 * </pre>
 */
class Factory
{
  public:


    /**
     * Returns the global resource factory.
     */
    static Factory *self( const QString& resourceFamily );

    ~Factory();

    /**
     * Returns the config widget for the given resource type,
     * or a null pointer if resource type doesn't exist.
     *
     * @param type   The type of the resource, returned by @ref resources()
     * @param resource The resource to be editted.
     * @param parent The parent widget
     */
    ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 );

    /**
     * Returns the sync widget for the given resource type,
     * or a null pointer if resource type doesn't exist,
     * or a null pointer if resource does not support syncing.
     *
     * @param type   The type of the resource, returned by @ref resources()
     * @param resource The resource to be editted.
     * @param parent The parent widget
     */
    SyncWidget *syncWidget( const QString& type, QWidget *parent = 0 );

    /**
     * Returns a pointer to a resource object or a null pointer
     * if resource type doesn't exist.
     *
     * @param type   The type of the resource, returned by @ref resources()
     * @param ab     The address book, the resource should belong to
     * @param config The config object where the resource get it settings from, or 0 if a new resource should be created.
     * @param syncable If the resource should support syncing capabilities.
     */
    Resource *resource( const QString& type, const KConfig *config, bool syncable );

    /**
     * Returns a list of all available resource types.
     */
    QStringList typeNames() const;

    /**
     * Returns the name for a special type.
     */
    QString typeName( const QString &type ) const;

    /**
     * Returns the description for a special type.
     */
    QString typeDescription( const QString &type ) const;

  protected:
    Factory( const QString& resourceFamily);

  private:
    static QDict<Factory> *mSelves;

    QString mResourceFamily;
//US    QMap<QString, KService::Ptr> mTypeMap;
//US lets store the pluginfo struct as value instead of a KService
    QMap<QString, PluginInfo*> mTypeMap;
};

}
#endif