autoquerylist.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <precomp.h>
  2. #include "autoquerylist.h"
  3. #include <api/db/subqueryserver.h>
  4. #include <api/db/multiqueryclient.h>
  5. #include <api/db/sharedscanner.h>
  6. #include <bfc/string/playstring.h>
  7. #include <api/db/metatags.h>
  8. #include <api/wnd/fakedrag.h>
  9. #include <bfc/util/profiler.h>
  10. #include <bfc/file/filename.h>
  11. #include <api/api.h>
  12. #include <api/service/svcs/svc_droptarget.h>
  13. #include <api/service/svc_enum.h>
  14. #include "../../pledit/svc_pldir.h"
  15. #include "../../pledit/playlist.h"
  16. #include "../../pledit/editor.h"
  17. #define TIMER_SCANNERDEL 0x6879
  18. #define DC_REFRESH 0x6880
  19. AutoQueryList::AutoQueryList() :
  20. playlist(NULL)
  21. {
  22. lastpc = -1;
  23. last_status_update = 0;
  24. pldir = NULL;
  25. nFound = 0;
  26. }
  27. AutoQueryList::~AutoQueryList() {
  28. getGuiObject()->guiobject_removeAppCmds(this);
  29. SvcEnum::release(pldir);
  30. }
  31. int AutoQueryList::onInit() {
  32. AUTOQUERYLIST_PARENT::onInit();
  33. pldir = SvcEnumByGuid<svc_plDir>();
  34. if (pldir != NULL) {
  35. PlaylistHandle hand = pldir->insertPlaylist(NULL, "Media library query results", NULL, TRUE);
  36. pldir->setAutoSave(hand, FALSE);
  37. playlist = pldir->getPlaylist(hand);
  38. playlist->lock(TRUE);
  39. }
  40. appcmds_addCmd("Reset", 0, AppCmds::SIDE_RIGHT);
  41. getGuiObject()->guiobject_addAppCmds(this);
  42. postDeferredCallback(DC_REFRESH, 0);
  43. return 1;
  44. }
  45. int AutoQueryList::onDeferredCallback(intptr_t p1, intptr_t p2) {
  46. if (p1 == DC_REFRESH) {
  47. mqs_refresh();
  48. return 0;
  49. }
  50. return AUTOQUERYLIST_PARENT::onDeferredCallback(p1, p2);
  51. }
  52. void AutoQueryList::mqs_onAddPlaystring(const char *playstring, int nitems, int thispos) {
  53. nfound++;
  54. stdtimevalms now = Std::getTimeStampMS();
  55. // if (n > lastpc) {
  56. if (now - last_status_update > 0.100) {
  57. int n = (int)(thispos / (float)nitems * 100.0f);
  58. getGuiObject()->guiobject_setCompleted(n);
  59. getGuiObject()->guiobject_setStatusText(StringPrintf("%d%c, %d item%s found", n, '%', nfound, (nfound > 1) ? "s" : ""), TRUE);
  60. // lastpc = n;
  61. // }
  62. last_status_update = now;
  63. }
  64. if (playlist != NULL)
  65. playlist->addPlaylistItem(playstring, Playlist::APPEND, FALSE);
  66. }
  67. void AutoQueryList::mqs_onCompleteMultiQuery() {
  68. getGuiObject()->guiobject_setStatusText(StringPrintf("100%c, %d item%s found", '%', nfound, (nfound > 1) ? "s" : ""), TRUE);
  69. lastpc = -1;
  70. getGuiObject()->guiobject_popCompleted();
  71. }
  72. void AutoQueryList::mqs_onNewMultiQuery() {
  73. nfound = 0;
  74. getGuiObject()->guiobject_setStatusText("0%", TRUE);
  75. getGuiObject()->guiobject_pushCompleted();
  76. if (playlist != NULL) {
  77. playlist->deleteAll();
  78. GuiObject *ed = getGuiObject()->guiobject_findObjectByInterface(Editor::getInterfaceGuid());
  79. if (ed != NULL) {
  80. Editor *e = static_cast<Editor*>(ed->guiobject_getRootWnd()->getInterface(Editor::getInterfaceGuid()));
  81. e->setPlaylistByHandle(playlist->getHandle());
  82. }
  83. }
  84. }
  85. void AutoQueryList::appcmds_onCommand(int id, const RECT *buttonRect, int which_btn) {
  86. switch (id) {
  87. case 0:
  88. resetSubQueries();
  89. break;
  90. }
  91. }
  92. void AutoQueryList::onSetVisible(int v) {
  93. AUTOQUERYLIST_PARENT::onSetVisible(v);
  94. if (!v) mqs_abort();
  95. }