dictcore.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*****************************************************************************
  2. * dictcore.h - QStarDict, a StarDict clone written with using Qt *
  3. * Copyright (C) 2007 Alexander Rodin *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, write to the Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  18. *****************************************************************************/
  19. #ifndef DICTCORE_H
  20. #define DICTCORE_H
  21. #include <QObject>
  22. #include <QStringList>
  23. #include <QPair>
  24. #include <QHash>
  25. #include "../plugins/dictplugin.h"
  26. namespace QStarDict
  27. {
  28. /**
  29. * The DictCore is a base dictionary class.
  30. */
  31. class DictCore: public QObject
  32. {
  33. Q_OBJECT
  34. public:
  35. /**
  36. * This class represents a dictionary.
  37. */
  38. class Dictionary
  39. {
  40. public:
  41. Dictionary(const QString &plugin, const QString &name)
  42. : m_plugin(plugin),
  43. m_name(name)
  44. { }
  45. Dictionary()
  46. { }
  47. const QString &plugin() const
  48. { return m_plugin; }
  49. const QString &name() const
  50. { return m_name; }
  51. void setPlugin(const QString &plugin)
  52. { m_plugin = plugin; }
  53. void setName(const QString &name)
  54. { m_name = name; }
  55. bool operator == (const Dictionary &dict)
  56. { return m_name == dict.m_name && m_plugin == dict.m_plugin; }
  57. private:
  58. QString m_plugin;
  59. QString m_name;
  60. };
  61. /**
  62. * Construct dictionary.
  63. */
  64. DictCore(QObject *parent = 0);
  65. /**
  66. * Destructor.
  67. */
  68. ~DictCore();
  69. /**
  70. * Returns true if word is exists in dictionaries,
  71. * otherwise false.
  72. */
  73. bool isTranslatable(const QString &word);
  74. /**
  75. * Returns translation for word. If word not found, returns
  76. * "Not found!"
  77. */
  78. QString translate(const QString &word);
  79. /**
  80. * Returns a list of similar words contained in dictionaries.
  81. */
  82. QStringList findSimilarWords(const QString &word);
  83. /**
  84. * Returns a list of available dictionaries.
  85. * The first item in pair is a plugin name, the second item
  86. * in pair is a dictionary name.
  87. */
  88. QList<Dictionary> availableDicts() const;
  89. /**
  90. * Returns a list of loaded dictionaries.
  91. * The first item in pair is a plugin name, the second item
  92. * in pair is a dictionary name.
  93. */
  94. const QList<Dictionary> &loadedDicts() const
  95. { return m_loadedDicts; }
  96. /**
  97. * Sets a loaded dictionaries.
  98. * The first item in pair is a plugin name, the second item
  99. * in pair is a dictionary name.
  100. * If dictionary cannot be loaded it will not be added to
  101. * availableDicts list.
  102. */
  103. void setLoadedDicts(const QList<Dictionary> &loadedDicts);
  104. /**
  105. * Reload loaded dicts.
  106. */
  107. void reloadDicts();
  108. /**
  109. * Save settings.
  110. */
  111. void saveSettings();
  112. private:
  113. /**
  114. * Load settings.
  115. */
  116. void loadSettings();
  117. QList<Dictionary> m_loadedDicts;
  118. };
  119. }
  120. #endif // DICTCORE_H
  121. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc