diff --git a/lib/DictEdict/dictfilefieldselector.h b/lib/DictEdict/dictfilefieldselector.h index 8cc8706..832e82e 100644 --- a/lib/DictEdict/dictfilefieldselector.h +++ b/lib/DictEdict/dictfilefieldselector.h @@ -1,69 +1,69 @@ /***************************************************************************** * This file is part of Kiten, a KDE Japanese Reference Tool * * Copyright (C) 2006 Joseph Kerian * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ //This is currently the only file in libkiten dict handlers to have moc code included... #ifndef KITEN_DICTFILEFIELDSELECTOR_H #define KITEN_DICTFILEFIELDSELECTOR_H #include "dictionarypreferencedialog.h" #include class KActionSelector; class KConfigSkeleton; class QString; class QStringList; //This is the default one used by edict and kanjidic class DictFileFieldSelector : public DictionaryPreferenceDialog { Q_OBJECT public: - DictFileFieldSelector( KConfigSkeleton *config + explicit DictFileFieldSelector( KConfigSkeleton *config , const QString &dictionaryTypeName , QWidget *parent ); virtual ~DictFileFieldSelector(); public slots: void setAvailable( const QStringList &list ); void addAvailable( const QStringList &list ); void setDefaultList( const QStringList &list ); void readFromPrefs(); void writeToPrefs(); void updateWidgets() override; void updateWidgetsDefault() override; void updateSettings() override; void settingChanged(); signals: void widgetChanged(); private: QStringList m_completeList; QStringList m_defaultList; QString m_dictName; KActionSelector *m_listView; KConfigSkeleton *m_config; }; #endif diff --git a/lib/entry.cpp b/lib/entry.cpp index 41cda33..a63d2e9 100644 --- a/lib/entry.cpp +++ b/lib/entry.cpp @@ -1,482 +1,482 @@ /***************************************************************************** * This file is part of Kiten, a KDE Japanese Reference Tool * * Copyright (C) 2001 Jason Katz-Brown * * Copyright (C) 2006 Joseph Kerian * * Copyright (C) 2006 Eric Kjeldergaard * * Copyright (C) 2011 Daniel E. Moctezuma * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #include "entry.h" #include "dictquery.h" #include #include #include #include #include /** * The default constructor, unless you really know what you're doing, * THIS SHOULD NOT BE USED. For general use, other entities will need * to have the information provided by the other constructors * (particularly the sourceDictionary). */ Entry::Entry() { init(); } Entry::Entry( const QString &sourceDictionary ) : sourceDict( sourceDictionary ) { init(); } Entry::Entry( const QString &sourceDictionary, const QString &word, const QStringList &reading, const QStringList &meanings ) : Word( word ) , Meanings( meanings ) , Readings( reading ) , sourceDict( sourceDictionary ) { init(); } Entry::Entry( const Entry &src ) : Word( src.Word ) , Meanings( src.Meanings ) , Readings( src.Readings ) , ExtendedInfo( src.ExtendedInfo ) , sourceDict( src.sourceDict ) { outputListDelimiter = src.outputListDelimiter; } Entry::~Entry() { // kdDebug() << "nuking : " << Word << endl; } bool Entry::extendedItemCheck( const QString& key, const QString &value ) const { return getExtendedInfoItem( key ) == value; } /** * Get the dictionary name that generated this Entry. I can't think of a reason to be changing this */ -const QString& Entry::getDictName() const +QString Entry::getDictName() const { return sourceDict; } /** * Get the word from this Entry. If the entry is of type kanji/kana/meaning/etc, this will return * the kanji. If it is of kana/meaning/etc, it will return kana. */ QString Entry::getWord() const { return Word; } /** * Get a QString containing all of the meanings known, connected by the outputListDelimiter */ QString Entry::getMeanings() const { return Meanings.join(outputListDelimiter); } /** * Simple accessor */ QStringList Entry::getMeaningsList() const { return Meanings; } /** * Simple accessor */ QString Entry::getReadings() const { return Readings.join( outputListDelimiter ); } /** * Simple accessor */ QStringList Entry::getReadingsList() const { return Readings; } /** * Simple accessor */ -const QHash &Entry::getExtendedInfo() const +QHash Entry::getExtendedInfo() const { return ExtendedInfo; } /** * Simple accessor * * @param x the key for the extended info item to get */ QString Entry::getExtendedInfoItem( const QString &x ) const { return ExtendedInfo[ x ]; } /** * Prepares Meanings for output as HTML */ inline QString Entry::HTMLMeanings() const { return QStringLiteral( "%1" ) .arg( Meanings.join( outputListDelimiter ) ); } /* Prepares Readings for output as HTML */ inline QString Entry::HTMLReadings() const { QStringList list; foreach( const QString &it, Readings ) { list += makeLink( it ); } return QStringLiteral( "%1" ) .arg( list.join( outputListDelimiter ) ); } /** * Prepares Word for output as HTML */ inline QString Entry::HTMLWord() const { return QStringLiteral( "%1" ).arg( Word ); } void Entry::init() { outputListDelimiter = i18n( "; " ); } /** * Determines whether @param character is a kanji character. */ bool Entry::isKanji( const QChar &character ) const { ushort value = character.unicode(); if( value < 255 ) { return false; } if( 0x3040 <= value && value <= 0x30FF ) { return false; //Kana } return true; //Note our folly here... we assuming any non-ascii/kana is kanji } /** * Returns true if all members of test are in list */ bool Entry::listMatch( const QStringList &list, const QStringList &test, DictQuery::MatchType type ) const { if( type == DictQuery::Exact ) { foreach( const QString &it, test ) { if( ! list.contains( it ) ) { return false; } } } else if( type == DictQuery::Beginning ) { foreach( const QString &it, test ) { bool found = false; foreach( const QString &it2, list ) { if( it2.startsWith( it ) ) { found = true; break; } } if( ! found ) { return false; } } } else if( type == DictQuery::Ending ) { foreach( const QString &it, test ) { bool found = false; foreach( const QString &it2, list ) { if( it2.endsWith( it ) ) { found = true; break; } } if( ! found ) { return false; } } } else { foreach( const QString &it, test ) { bool found = false; foreach( const QString &it2, list ) { if( it2.contains( it ) ) { found = true; break; } } if( ! found ) { return false; } } } return true; } /** * New functions for Entry doing direct display. * * Creates a link for the given @p entryString. */ inline QString Entry::makeLink( const QString &entryString ) const { return QStringLiteral( "%1" ).arg( entryString ); } bool Entry::matchesQuery( const DictQuery &query ) const { if( ! query.getWord().isEmpty() ) { if( query.getMatchType() == DictQuery::Exact && this->getWord() != query.getWord() ) { return false; } if( query.getMatchType() == DictQuery::Beginning && ! this->getWord().startsWith( query.getWord() ) ) { return false; } if( query.getMatchType() == DictQuery::Ending && ! this->getWord().endsWith( query.getWord() ) ) { return false; } if( query.getMatchType() == DictQuery::Anywhere && ! this->getWord().contains( query.getWord() ) ) { return false; } } if( ! query.getPronunciation().isEmpty() && ! getReadings().isEmpty() ) { if( ! listMatch( Readings, query.getPronunciation().split( DictQuery::mainDelimiter ), query.getMatchType() ) ) { return false; } } if( ! query.getPronunciation().isEmpty() && getReadings().isEmpty() && ! getWord().isEmpty() ) { switch ( query.getMatchType() ) { case DictQuery::Exact: if ( getWord() != query.getPronunciation() ) { return false; } break; case DictQuery::Beginning: if ( ! getWord().startsWith( query.getPronunciation() ) ) { return false; } break; case DictQuery::Ending: if ( ! getWord().endsWith( query.getPronunciation() ) ) { return false; } //fallthrough case DictQuery::Anywhere: if ( ! getWord().contains( query.getPronunciation() ) ) { return false; } break; } } if( ! query.getMeaning().isEmpty() ) { if( ! listMatch( Meanings.join(QLatin1Char(' ') ).toLower().split( ' ' ) , query.getMeaning().toLower().split( DictQuery::mainDelimiter ) , query.getMatchType() ) ) { return false; } } QList propList = query.listPropertyKeys(); foreach( const QString &key, propList ) { if( ! extendedItemCheck( key, query.getProperty( key ) ) ) { return false; } } return true; } /** * Main switching function for displaying to the user */ QString Entry::toHTML() const { return QStringLiteral( "
%1%2%3
" ) .arg( HTMLWord() ) .arg( HTMLReadings() ) .arg( HTMLMeanings() ); } inline QString Entry::toKVTML() const { /* (eh,) excuse me (あのう、) すみません */ //TODO: en should not necessarily be the language here. return QString( "\n%1\n" "%2\n" "%3\n\n" ).arg( getMeanings() ) .arg( getWord() ) .arg( getReadings() ); } /** * This method should return the entry object in a simple QString format * Brief form should be usable in quick summaries, for example * Verbose form might be used to save a complete list of entries to a file, for example. */ QString Entry::toString() const { return QStringLiteral( "%1 (%2) %3" ).arg( Word ) .arg( getReadings() ) .arg( getMeanings() ); } /** * This version of sort only sorts dictionaries... * This is a replacement for an operator\< function... so we return true if * "this" should show up first on the list. */ bool Entry::sort( const Entry &that, const QStringList &dictOrder, const QStringList &fields ) const { if( this->sourceDict != that.sourceDict ) { foreach( const QString &dict, dictOrder ) { if( dict == that.sourceDict ) { return false; } if( dict == this->sourceDict ) { return true; } } } else { foreach( const QString &field, fields ) { if( field == QLatin1String( "Word/Kanji" ) ) { return this->getWord() < that.getWord(); } else if( field == QLatin1String( "Meaning" ) ) { return listMatch( that.getMeaningsList(), this->getMeaningsList(), DictQuery::Exact ) && ( that.getMeaningsList().count() != this->getMeaningsList().count() ); } else if( field == QLatin1String( "Reading" ) ) { return listMatch( that.getReadingsList(), this->getReadingsList(), DictQuery::Exact ) && ( that.getReadingsList().count() != this->getReadingsList().count() ); } else { const QString thisOne = this->getExtendedInfoItem( field ); const QString thatOne = that.getExtendedInfoItem( field ); //Only sort by this field if the values differ, otherwise move to the next field if( thisOne != thatOne ) { //If the second item does not have this field, sort this one first if( thatOne.isEmpty() ) { return true; } //If we don't have this field, sort "this" to second if( thisOne.isEmpty() ) { return false; } //Otherwise, send it to a virtual function (to allow dictionaries to override sorting) return this->sortByField( that, field ); } } } } return false; //If we reach here, they match as much as possible } bool Entry::sortByField( const Entry &that, const QString &field ) const { return this->getExtendedInfoItem( field ) < that.getExtendedInfoItem( field ); } diff --git a/lib/entry.h b/lib/entry.h index 7a22525..d8e37fb 100644 --- a/lib/entry.h +++ b/lib/entry.h @@ -1,249 +1,249 @@ /***************************************************************************** * This file is part of Kiten, a KDE Japanese Reference Tool * * Copyright (C) 2001 Jason Katz-Brown * * Copyright (C) 2006 Joseph Kerian * * Copyright (C) 2006 Eric Kjeldergaard * * Copyright (C) 2011 Daniel E. Moctezuma * * * * 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., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * *****************************************************************************/ #ifndef KITEN_ENTRY_H #define KITEN_ENTRY_H #include #include #include "kiten_export.h" #include "dictquery.h" class Entry; class EntryList; class QString; /** * The Entry class is a generic base class for each particular entry in a given dictionary. * It's used as the basic class to ferry information back to the user application. * It also handles some of the display aspects. */ class KITEN_EXPORT Entry { friend class EntryListModel; private: /** * Default constructor, should not be used. Made private to serve as a warning * that you're doing something wrong if you try to call this. */ Entry(); protected: /** * Copy constructor */ Entry( const Entry& ); /** * Constructor that includes the dictionary source. This does not need to be overridden by * subclasses, but you might find it to be convenient as the superclass constructor to call * from your constructors. * @param sourceDictionary the dictionary name (not fileName) that this entry originated with */ Entry( const QString &sourceDictionary ); /** * A constructor that includes the basic information, nicely separated * @param sourceDictionary the dictionary name (not fileName) that this entry originated with * @param word the word entry of this dictionary entry (normally kanji/kana) * @param readings a list of possible pronunciations for this result (kana) * @param meanings a list of possible meanings for this word */ Entry( const QString &sourceDictionary, const QString &word, const QStringList &readings, const QStringList &meanings ); public: /** * Generic Destructor */ virtual ~Entry(); /** * A clone method, this should just implement "return new EntrySubClass(*this)" */ virtual Entry *clone() const = 0; /** * Fairly important method, this tests if this particular entry matches a query. The * EDICT and Kanjidic doSearch methods do an approximate match, load an Entry, and then * check more carefully by calling this method. This works nicely for handling searchWithinResults * cleanly. */ virtual bool matchesQuery( const DictQuery& ) const; /** * Get the dictionary name that generated this Entry. I can't think of a reason to be changing this */ - const QString &getDictName() const; + QString getDictName() const; /** * Get the dictionary type (e.g. edict, kanjidic). */ virtual QString getDictionaryType() const = 0; /** * Get the word from this Entry. If the entry is of type kanji/kana/meaning/etc, this will * return the kanji. If it is of kana/meaning/etc, it will return kana. */ QString getWord() const; /** * Get a QString containing all of the meanings known, connected by the outputListDelimiter */ QString getMeanings() const; /** * Simple accessor */ QStringList getMeaningsList() const; /** * Simple accessor */ QString getReadings() const; /** * Simple accessor */ QStringList getReadingsList() const; /** * Simple accessor */ - const QHash &getExtendedInfo() const; + QHash getExtendedInfo() const; /** * Simple accessor * @param x the key for the extended info item to get */ QString getExtendedInfoItem( const QString &x ) const; /** * Simple accessor * @param key the key for the extended item that is being verified * @param value the value it is supposed to have * @returns true if the key has that value, false if it is different or does not exist */ virtual bool extendedItemCheck( const QString &key, const QString &value ) const; /** * An entry should be able to generate a representation of itself in (valid) HTML */ virtual QString toHTML() const; /** * KVTML format for exporting */ virtual QString toKVTML() const; /** * This will return a pure text interpretation of the Entry */ virtual QString toString() const; /** * An entry should be able to parse an in-file representation of an entry * as a QString and put it back. The latter will be useful for writing * to dictionaries on disk at some point. */ virtual bool loadEntry( const QString& ) = 0; /** * Return a QString of an entry, as if it were dumped back into it's source file */ virtual QString dumpEntry() const = 0; /** * An overrideable sorting function, similar to operator< in most contexts * The default version will sort by dictionary, then by fields * * @param that the second item we are comparing (this) with * @param dictOrder the list of dictionaries (in order) to sort * If this list is empty, the entries will not be sorted in order * @param fields the list of fields to sort in, uses special codes of * Reading, Meaning, Word/Kanji for those elements, all others by their * extended attribute keys. */ virtual bool sort( const Entry &that, const QStringList &dictOrder, const QStringList &fields ) const; /** * Overrideable sorting mechanism for sorting by individual fields. * The sort routine checks if the given field is equal, before calling this virtual function * So if this is called, you can assume that this->extendedItem(field) != that.extendedItem(field) * * @param that the second item we are comparing (this) with * @param field the specific extended item field that is being compared */ virtual bool sortByField( const Entry &that, const QString &field ) const; protected: /** * The Word (usually containing kanji) that matches this entry. If you override the accessors * above, this has no use. */ QString Word; /** * The Meanings that match this entry. If you override the accessors * above, this has no use. */ QStringList Meanings; /** * The Readings (usually kana) that match this entry. If you override the accessors * above, this has no use. */ QStringList Readings; /** * A hash of extended information. You may find it useful to store all sorts of details here */ QHash ExtendedInfo; /** * The dictionary that this entry originated at */ QString sourceDict; /** * The delimiter for lists... usually space */ QString outputListDelimiter; /** * This is used by the constructors to set some default values */ void init(); /** * Handy function for generating a link from a given QString */ virtual QString makeLink( const QString &entryString ) const; /** * Return and HTML version of a word */ virtual QString HTMLWord() const; /** * Return and HTML version of a reading list */ virtual QString HTMLReadings() const; /** * Return and HTML version of a meaning list */ virtual QString HTMLMeanings() const; /** * Handy Utility functions for matching to lists and identifying char types */ bool listMatch( const QStringList &list, const QStringList &test, DictQuery::MatchType type ) const; /** * Handy Utility functions for matching to lists and identifying char types */ bool isKanji( const QChar &character ) const; }; #endif