Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cswordsetupmodulelistview.cpp 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #include "cswordsetupmodulelistview.h"
  10. #include "btinstallmgr.h"
  11. #include "backend/cswordbackend.h"
  12. #include "backend/cswordmoduleinfo.h"
  13. #include "util/cresmgr.h"
  14. #include "util/ctoolclass.h"
  15. //QT includes
  16. #include <tqtooltip.h>
  17. //KDE includes
  18. #include <tdelocale.h>
  19. #include <kiconloader.h>
  20. using namespace sword;
  21. namespace BookshelfManager {
  22. /** Tooltip implementation for TQListView widgets.
  23. * @short Tooltip for InstallationManager listviews
  24. * @author Joachim Ansorg
  25. */
  26. class ToolTip : public TQToolTip {
  27. public:
  28. /** Constructor which takes the listview to operate on.
  29. * @param listview We operate on this widget to request tooltips from it'd child items.
  30. * @short Constructor.
  31. */
  32. ToolTip(CSwordSetupModuleListView* listview)
  33. : TQToolTip( listview->viewport() ),
  34. m_parent( listview ) {}
  35. /** Reimplementation of TQToolTip::maybeTip. It's requested if a new tooltip may be displayed.
  36. * @short Display a tooltip if we're over an item
  37. */
  38. virtual void maybeTip(const TQPoint& pos) {
  39. TQListViewItem* i = m_parent->itemAt(pos);
  40. Q_ASSERT(i);
  41. const TQRect rect = m_parent->itemRect(i);
  42. if (m_parent->showTooltip(i, pos, 0)) {
  43. const TQString tipText = m_parent->tooltip(i, 0);
  44. tip(rect, tipText);
  45. }
  46. }
  47. protected:
  48. CSwordSetupModuleListView* m_parent;
  49. };
  50. /** Listview specially made for the installation manager.
  51. * @short InstallationManager module listviews
  52. * @author Martin Gruner
  53. */
  54. CSwordSetupModuleListView::CSwordSetupModuleListView(TQWidget *parent, bool is_remote, sword::InstallSource* installSource)
  55. : TDEListView(parent), m_is_remote( is_remote ) {
  56. Q_ASSERT(installSource);
  57. new BookshelfManager::ToolTip(this);
  58. m_backend = installSource ? BTInstallMgr::Tool::backend(installSource) : CPointers::backend();
  59. addColumn(i18n("Name"));
  60. setColumnWidthMode( 0, TQListView::Maximum );
  61. setColumnWidth( 0, 200 ); //don`t get too broad
  62. addColumn(i18n("Status"));
  63. setColumnAlignment(1, TQt::AlignRight);
  64. addColumn(i18n("Installed version")); //version
  65. setColumnAlignment(2, TQt::AlignHCenter);
  66. if (m_is_remote) {
  67. addColumn(i18n("Remote version")); //version
  68. } else {
  69. addColumn(i18n("Location"));
  70. }
  71. setColumnAlignment(3, TQt::AlignLeft);
  72. setAllColumnsShowFocus(true);
  73. setFullWidth(true);
  74. setRootIsDecorated(true);
  75. setResizeMode(TQListView::LastColumn);
  76. setTooltipColumn(0);
  77. init();
  78. }
  79. CSwordSetupModuleListView::~CSwordSetupModuleListView() {
  80. if (m_is_remote) {
  81. delete m_backend;
  82. }
  83. }
  84. void CSwordSetupModuleListView::init() {
  85. m_categoryBible = new TQCheckListItem(this, i18n("Bibles"), TQCheckListItem::CheckBoxController);
  86. m_categoryCommentary = new TQCheckListItem(this, i18n("Commentaries"), TQCheckListItem::CheckBoxController);
  87. m_categoryLexicon = new TQCheckListItem(this, i18n("Lexicons"), TQCheckListItem::CheckBoxController);
  88. m_categoryBook = new TQCheckListItem(this, i18n("Books"), TQCheckListItem::CheckBoxController);
  89. m_categoryDevotionals = new TQCheckListItem(this, i18n("Daily Devotionals"), TQCheckListItem::CheckBoxController);
  90. m_categoryGlossaries = new TQCheckListItem(this, i18n("Glossaries"), TQCheckListItem::CheckBoxController);
  91. m_categoryBible->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  92. m_categoryCommentary->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  93. m_categoryLexicon->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  94. m_categoryBook->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  95. m_categoryDevotionals->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  96. m_categoryGlossaries->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  97. m_categoryBible->setOpen(true);
  98. m_categoryCommentary->setOpen(true);
  99. m_categoryLexicon->setOpen(true);
  100. m_categoryBook->setOpen(true);
  101. m_categoryDevotionals->setOpen(true);
  102. m_categoryGlossaries->setOpen(true);
  103. // connect(this, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(slotItemClicked(TQListViewItem*)));
  104. connect(this, TQT_SIGNAL(clicked(TQListViewItem*)), TQT_SLOT(slotItemClicked(TQListViewItem*))); //items have to be clicked only once in double click mode
  105. connect(this, TQT_SIGNAL(spacePressed(TQListViewItem*)), TQT_SLOT(slotItemClicked(TQListViewItem*)));
  106. }
  107. void CSwordSetupModuleListView::finish() {
  108. if (!m_categoryBible->childCount())
  109. delete m_categoryBible;
  110. if (!m_categoryCommentary->childCount())
  111. delete m_categoryCommentary;
  112. if (!m_categoryBook->childCount())
  113. delete m_categoryBook;
  114. if (!m_categoryLexicon->childCount())
  115. delete m_categoryLexicon;
  116. if (!m_categoryDevotionals->childCount())
  117. delete m_categoryDevotionals;
  118. if (!m_categoryGlossaries->childCount())
  119. delete m_categoryGlossaries;
  120. }
  121. void CSwordSetupModuleListView::clear() {
  122. TQListView::clear();
  123. init();
  124. }
  125. void CSwordSetupModuleListView::addModule(CSwordModuleInfo* module, TQString localVersion) {
  126. TQListViewItem* parent = 0;
  127. switch ( module->type() ) {
  128. case CSwordModuleInfo::Bible:
  129. parent = m_categoryBible;
  130. break;
  131. case CSwordModuleInfo::Commentary:
  132. parent = m_categoryCommentary;
  133. break;
  134. case CSwordModuleInfo::Lexicon:
  135. parent = m_categoryLexicon;
  136. break;
  137. case CSwordModuleInfo::GenericBook:
  138. parent = m_categoryBook;
  139. break;
  140. default:
  141. parent = 0;
  142. break;
  143. }
  144. //handling for special module types
  145. if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::Glossary)) {
  146. parent = m_categoryGlossaries;
  147. }
  148. if ((parent == m_categoryLexicon) && (module->category() == CSwordModuleInfo::DailyDevotional)) {
  149. parent = m_categoryDevotionals;
  150. }
  151. //now we know the category, find the right language group in that category
  152. const CLanguageMgr::Language* const lang = module->language();
  153. TQString langName = lang->translatedName();
  154. if (!lang->isValid()) {
  155. langName = TQString(module->module()->Lang());
  156. }
  157. TQListViewItem * langFolder = 0;
  158. if (parent) {
  159. langFolder = parent->firstChild();
  160. while( langFolder ) { //try to find language folder if it exsists
  161. if (langFolder->text(0) == langName) { //found right folder
  162. break;
  163. }
  164. langFolder = langFolder->nextSibling();
  165. }
  166. }
  167. if (!langFolder) { //not yet there
  168. langFolder = new TQCheckListItem(parent, langName, TQCheckListItem::CheckBoxController);
  169. langFolder->setPixmap(0, SmallIcon(CResMgr::mainIndex::closedFolder::icon, 16));
  170. langFolder->setOpen(false);
  171. }
  172. Q_ASSERT(langFolder);
  173. TQListViewItem* newItem = 0;
  174. if (langFolder) {
  175. newItem = new TQCheckListItem(langFolder, module->name(), TQCheckListItem::CheckBox);
  176. } else { //shouldn't happen
  177. newItem = new TQCheckListItem(this, module->name(), TQCheckListItem::CheckBox);
  178. }
  179. newItem->setPixmap(0, CToolClass::getIconForModule(module));
  180. if (m_is_remote) {
  181. newItem->setText(1, localVersion.isEmpty() ? i18n("New") : i18n("Updated"));
  182. } else {
  183. newItem->setText(1, i18n("Installed") );
  184. }
  185. newItem->setText(2, localVersion);
  186. if (m_is_remote) {
  187. newItem->setText(3, module->config(CSwordModuleInfo::ModuleVersion));
  188. } else {
  189. newItem->setText(3, module->config(CSwordModuleInfo::AbsoluteDataPath));
  190. }
  191. }
  192. TQStringList CSwordSetupModuleListView::selectedModules() {
  193. TQStringList moduleList;
  194. TQListViewItemIterator list_it( this );
  195. while ( list_it.current() ) {
  196. TQCheckListItem* i = dynamic_cast<TQCheckListItem*>( list_it.current() );
  197. if (i && i->isOn() && i->type() == TQCheckListItem::CheckBox ) {
  198. moduleList << i->text(0);
  199. }
  200. ++list_it;
  201. }
  202. return moduleList;
  203. }
  204. void CSwordSetupModuleListView::slotItemClicked(TQListViewItem*) {
  205. emit selectedModulesChanged();
  206. }
  207. bool CSwordSetupModuleListView::showTooltip(TQListViewItem* i, const TQPoint&, int) const {
  208. TQCheckListItem* checkItem = dynamic_cast<TQCheckListItem*>( i );
  209. Q_ASSERT(checkItem);
  210. return (checkItem && (checkItem->type() == TQCheckListItem::CheckBox));
  211. }
  212. TQString CSwordSetupModuleListView::tooltip(TQListViewItem* i, int /*column*/) const {
  213. TQString ret;
  214. TQCheckListItem* checkItem = dynamic_cast<TQCheckListItem*>( i );
  215. if (checkItem && (checkItem->type() == TQCheckListItem::CheckBox)) {
  216. const TQString moduleName = checkItem->text(0);
  217. CSwordModuleInfo* module = m_backend->findModuleByName(moduleName);
  218. ret = CToolClass::moduleToolTip(module);
  219. }
  220. return ret;
  221. }
  222. } //NAMESPACE
  223. #include "cswordsetupmodulelistview.moc"