Tellico – collection manager for books, videos, music
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.

203 lines
8.1KB

  1. /***************************************************************************
  2. copyright : (C) 2003-2006 by Robby Stephenson
  3. email : robby@periapsis.org
  4. ***************************************************************************/
  5. /***************************************************************************
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of version 2 of the GNU General Public License as *
  9. * published by the Free Software Foundation; *
  10. * *
  11. ***************************************************************************/
  12. #include "bookcollection.h"
  13. #include <tdelocale.h>
  14. namespace {
  15. static const char* book_general = I18N_NOOP("General");
  16. static const char* book_publishing = I18N_NOOP("Publishing");
  17. static const char* book_classification = I18N_NOOP("Classification");
  18. static const char* book_personal = I18N_NOOP("Personal");
  19. }
  20. using Tellico::Data::BookCollection;
  21. BookCollection::BookCollection(bool addFields_, const TQString& title_ /*=null*/)
  22. : Collection(title_.isEmpty() ? i18n("My Books") : title_) {
  23. if(addFields_) {
  24. addFields(defaultFields());
  25. }
  26. setDefaultGroupField(TQString::fromLatin1("author"));
  27. }
  28. Tellico::Data::FieldVec BookCollection::defaultFields() {
  29. FieldVec list;
  30. FieldPtr field;
  31. field = new Field(TQString::fromLatin1("title"), i18n("Title"));
  32. field->setCategory(i18n("General"));
  33. field->setFlags(Field::NoDelete);
  34. field->setFormatFlag(Field::FormatTitle);
  35. list.append(field);
  36. field = new Field(TQString::fromLatin1("subtitle"), i18n("Subtitle"));
  37. field->setCategory(i18n(book_general));
  38. field->setFormatFlag(Field::FormatTitle);
  39. list.append(field);
  40. field = new Field(TQString::fromLatin1("author"), i18n("Author"));
  41. field->setCategory(i18n(book_general));
  42. field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
  43. field->setFormatFlag(Field::FormatName);
  44. list.append(field);
  45. field = new Field(TQString::fromLatin1("editor"), i18n("Editor"));
  46. field->setCategory(i18n(book_general));
  47. field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
  48. field->setFormatFlag(Field::FormatName);
  49. list.append(field);
  50. TQStringList binding;
  51. binding << i18n("Hardback") << i18n("Paperback") << i18n("Trade Paperback")
  52. << i18n("E-Book") << i18n("Magazine") << i18n("Journal");
  53. field = new Field(TQString::fromLatin1("binding"), i18n("Binding"), binding);
  54. field->setCategory(i18n(book_general));
  55. field->setFlags(Field::AllowGrouped);
  56. list.append(field);
  57. field = new Field(TQString::fromLatin1("pur_date"), i18n("Purchase Date"));
  58. field->setCategory(i18n(book_general));
  59. field->setFormatFlag(Field::FormatDate);
  60. list.append(field);
  61. field = new Field(TQString::fromLatin1("pur_price"), i18n("Purchase Price"));
  62. field->setCategory(i18n(book_general));
  63. list.append(field);
  64. field = new Field(TQString::fromLatin1("publisher"), i18n("Publisher"));
  65. field->setCategory(i18n(book_publishing));
  66. field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
  67. field->setFormatFlag(Field::FormatPlain);
  68. list.append(field);
  69. field = new Field(TQString::fromLatin1("edition"), i18n("Edition"));
  70. field->setCategory(i18n(book_publishing));
  71. field->setFlags(Field::AllowCompletion);
  72. field->setFormatFlag(Field::FormatPlain);
  73. list.append(field);
  74. field = new Field(TQString::fromLatin1("cr_year"), i18n("Copyright Year"), Field::Number);
  75. field->setCategory(i18n(book_publishing));
  76. field->setFlags(Field::AllowGrouped | Field::AllowMultiple);
  77. list.append(field);
  78. field = new Field(TQString::fromLatin1("pub_year"), i18n("Publication Year"), Field::Number);
  79. field->setCategory(i18n(book_publishing));
  80. field->setFlags(Field::AllowGrouped);
  81. list.append(field);
  82. field = new Field(TQString::fromLatin1("isbn"), i18n("ISBN#"));
  83. field->setCategory(i18n(book_publishing));
  84. field->setDescription(i18n("International Standard Book Number"));
  85. list.append(field);
  86. field = new Field(TQString::fromLatin1("lccn"), i18n("LCCN#"));
  87. field->setCategory(i18n(book_publishing));
  88. field->setDescription(i18n("Library of Congress Control Number"));
  89. list.append(field);
  90. field = new Field(TQString::fromLatin1("pages"), i18n("Pages"), Field::Number);
  91. field->setCategory(i18n(book_publishing));
  92. list.append(field);
  93. field = new Field(TQString::fromLatin1("translator"), i18n("Translator"));
  94. field->setCategory(i18n(book_publishing));
  95. field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
  96. field->setFormatFlag(Field::FormatName);
  97. list.append(field);
  98. field = new Field(TQString::fromLatin1("language"), i18n("Language"));
  99. field->setCategory(i18n(book_publishing));
  100. field->setFlags(Field::AllowCompletion | Field::AllowGrouped | Field::AllowMultiple);
  101. list.append(field);
  102. field = new Field(TQString::fromLatin1("genre"), i18n("Genre"));
  103. field->setCategory(i18n(book_classification));
  104. field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
  105. list.append(field);
  106. // in document versions < 3, this was "keywords" and not "keyword"
  107. // but the title didn't change, only the name
  108. field = new Field(TQString::fromLatin1("keyword"), i18n("Keywords"));
  109. field->setCategory(i18n(book_classification));
  110. field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
  111. list.append(field);
  112. field = new Field(TQString::fromLatin1("series"), i18n("Series"));
  113. field->setCategory(i18n(book_classification));
  114. field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
  115. list.append(field);
  116. field = new Field(TQString::fromLatin1("series_num"), i18n("Series Number"), Field::Number);
  117. field->setCategory(i18n(book_classification));
  118. list.append(field);
  119. TQStringList cond;
  120. cond << i18n("New") << i18n("Used");
  121. field = new Field(TQString::fromLatin1("condition"), i18n("Condition"), cond);
  122. field->setCategory(i18n(book_classification));
  123. list.append(field);
  124. field = new Field(TQString::fromLatin1("signed"), i18n("Signed"), Field::Bool);
  125. field->setCategory(i18n(book_personal));
  126. list.append(field);
  127. field = new Field(TQString::fromLatin1("read"), i18n("Read"), Field::Bool);
  128. field->setCategory(i18n(book_personal));
  129. list.append(field);
  130. field = new Field(TQString::fromLatin1("gift"), i18n("Gift"), Field::Bool);
  131. field->setCategory(i18n(book_personal));
  132. list.append(field);
  133. field = new Field(TQString::fromLatin1("loaned"), i18n("Loaned"), Field::Bool);
  134. field->setCategory(i18n(book_personal));
  135. list.append(field);
  136. field = new Field(TQString::fromLatin1("rating"), i18n("Rating"), Field::Rating);
  137. field->setCategory(i18n(book_personal));
  138. field->setFlags(Field::AllowGrouped);
  139. list.append(field);
  140. field = new Field(TQString::fromLatin1("cover"), i18n("Front Cover"), Field::Image);
  141. list.append(field);
  142. field = new Field(TQString::fromLatin1("comments"), i18n("Comments"), Field::Para);
  143. field->setCategory(i18n(book_personal));
  144. list.append(field);
  145. return list;
  146. }
  147. int BookCollection::sameEntry(Data::EntryPtr entry1_, Data::EntryPtr entry2_) const {
  148. // equal isbn's or lccn's are easy, give it a weight of 100
  149. if(Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("isbn"), this) > 0 ||
  150. Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("lccn"), this) > 0) {
  151. return 100; // good match
  152. }
  153. int res = 3*Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("title"), this);
  154. // if(res == 0) {
  155. // myDebug() << "BookCollection::sameEntry() - different titles for " << entry1_->title() << " vs. "
  156. // << entry2_->title() << endl;
  157. // }
  158. res += 2*Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("author"), this);
  159. res += Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("cr_year"), this);
  160. res += Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("pub_year"), this);
  161. res += Entry::compareValues(entry1_, entry2_, TQString::fromLatin1("binding"), this);
  162. return res;
  163. }
  164. #include "bookcollection.moc"