2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __INSTANCES_HH_INCLUDED__
|
|
|
|
#define __INSTANCES_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include "config.hh"
|
|
|
|
#include "dictionary.hh"
|
2009-10-21 19:33:23 +00:00
|
|
|
#include <QIcon>
|
2010-05-08 14:01:59 +00:00
|
|
|
#include <limits.h>
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
// This complements Config, providing instances for the stored configurations.
|
|
|
|
// Simply put, it can convert groups to ones which hold references to
|
|
|
|
// dictionaries directly, instead of only having their ids, and can also convert
|
|
|
|
// them back.
|
|
|
|
|
|
|
|
namespace Instances {
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
struct Group
|
|
|
|
{
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned id;
|
2009-01-28 20:55:45 +00:00
|
|
|
QString name, icon;
|
2010-07-05 18:36:03 +00:00
|
|
|
QIcon iconData;
|
2010-07-05 14:13:29 +00:00
|
|
|
QKeySequence shortcut;
|
2009-01-28 20:55:45 +00:00
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
|
|
|
|
|
|
|
/// Instantiates the given group from its configuration. If some dictionary
|
|
|
|
/// wasn't found, it just skips it.
|
|
|
|
Group( Config::Group const & cfgGroup,
|
|
|
|
vector< sptr< Dictionary::Class > > const & allDictionaries );
|
|
|
|
|
|
|
|
/// Creates an empty group.
|
|
|
|
Group( QString const & name_ );
|
|
|
|
|
|
|
|
/// Makes the configuration group from the current contents.
|
|
|
|
Config::Group makeConfigGroup();
|
2009-10-21 19:33:23 +00:00
|
|
|
|
2010-07-05 18:36:03 +00:00
|
|
|
/// Makes an icon object for this group, based on the icon's name or iconData.
|
2009-10-21 19:33:23 +00:00
|
|
|
QIcon makeIcon() const;
|
2010-05-08 14:01:59 +00:00
|
|
|
|
|
|
|
// Some constants
|
|
|
|
|
|
|
|
/// The id of the 'All' group
|
|
|
|
static const unsigned AllGroupId = UINT_MAX - 1;
|
|
|
|
|
|
|
|
/// The id of the fictious 'Help' group
|
|
|
|
static const unsigned HelpGroupId = UINT_MAX;
|
|
|
|
|
|
|
|
/// Invalid value, used to specify that no group id is specified at all.
|
|
|
|
static const unsigned NoGroupId = 0;
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
2009-05-14 19:27:19 +00:00
|
|
|
struct Groups: public vector< Group >
|
|
|
|
{
|
|
|
|
/// Tries finding the given group by its id. Returns the group found, or
|
|
|
|
/// 0 if there's no such group.
|
|
|
|
Group * findGroup( unsigned id );
|
|
|
|
Group const * findGroup( unsigned id ) const;
|
|
|
|
};
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
/// Adds any dictionaries not already present in the given group or in
|
|
|
|
/// inactiveDictionaires to its end. Meant to be used with dictionaryOrder
|
|
|
|
/// special group.
|
2009-05-23 14:19:57 +00:00
|
|
|
void complementDictionaryOrder( Group & dictionaryOrder,
|
|
|
|
Group const & inactiveDictionaries,
|
2009-05-18 18:01:50 +00:00
|
|
|
vector< sptr< Dictionary::Class > > const &
|
|
|
|
allDictionaries );
|
|
|
|
|
2009-04-01 12:00:28 +00:00
|
|
|
/// For any dictionaries present in the group, updates their names to match
|
|
|
|
/// the dictionaries they refer to in their current form, if they exist.
|
|
|
|
/// If the dictionary instance can't be located, the name is left untouched.
|
|
|
|
void updateNames( Config::Group &,
|
|
|
|
vector< sptr< Dictionary::Class > > const & allDictionaries );
|
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
/// Does updateNames() for a set of given groups.
|
|
|
|
void updateNames( Config::Groups &,
|
|
|
|
vector< sptr< Dictionary::Class > > const & allDictionaries );
|
|
|
|
|
|
|
|
/// Does updateNames() for any relevant dictionary groups present in the
|
|
|
|
/// configuration.
|
|
|
|
void updateNames( Config::Class &,
|
|
|
|
vector< sptr< Dictionary::Class > > const & allDictionaries );
|
|
|
|
|
2010-07-05 18:36:03 +00:00
|
|
|
/// Creates icon from icon data. Used by Group, but also by others who work
|
|
|
|
/// with icon data directly.
|
|
|
|
QIcon iconFromData( QByteArray const & );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|