Ticket #355: mythmusic_search.patch
File mythmusic_search.patch, 11.5 KB (added by , 19 years ago) |
---|
-
mythplugins-0.18.1/mythmusic/
old new HEADERS += metaioflacvorbiscomment.h met 34 34 HEADERS += goom/filters.h goom/goomconfig.h goom/goom_core.h goom/graphic.h 35 35 HEADERS += goom/ifs.h goom/lines.h goom/mythgoom.h goom/drawmethods.h 36 36 HEADERS += goom/mmx.h goom/mathtools.h goom/tentacle3d.h goom/v3d.h 37 HEADERS += editmetadata.h smartplaylist.h 37 HEADERS += editmetadata.h smartplaylist.h search.h 38 38 39 39 SOURCES += cddecoder.cpp cdrip.cpp decoder.cpp 40 40 SOURCES += flacdecoder.cpp flacencoder.cpp maddecoder.cpp main.cpp … … SOURCES += metaioflacvorbiscomment.cpp m 48 48 SOURCES += goom/filters.c goom/goom_core.c goom/graphic.c goom/tentacle3d.c 49 49 SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c 50 50 SOURCES += goom/zoom_filter_mmx.c goom/zoom_filter_xmmx.c goom/mythgoom.cpp 51 SOURCES += avfdecoder.cpp editmetadata.cpp smartplaylist.cpp 51 SOURCES += avfdecoder.cpp editmetadata.cpp smartplaylist.cpp search.cpp -
mythplugins-0.18.1/mythmusic/
old new using namespace std; 13 13 #include "databasebox.h" 14 14 #include "mainvisual.h" 15 15 #include "smartplaylist.h" 16 #include "search.h" 16 17 17 18 #include <mythtv/mythcontext.h> 18 19 #include <mythtv/mythwidgets.h> … … void PlaybackBoxMusic::showMenu() 434 435 splitter->setMaximumHeight((int) (5 * hmult)); 435 436 splitter->setMaximumHeight((int) (5 * hmult)); 436 437 438 playlist_popup->addButton(tr("Search"), this, 439 SLOT(showSearchDialog())); 440 441 splitter = playlist_popup->addLabel(" ", MythPopupBox::Small); 442 splitter->setLineWidth(2); 443 splitter->setFrameShape(QFrame::HLine); 444 splitter->setFrameShadow(QFrame::Sunken); 445 splitter->setMaximumHeight((int) (5 * hmult)); 446 splitter->setMaximumHeight((int) (5 * hmult)); 447 437 448 playlist_popup->addButton(tr("All Tracks"), this, 438 449 SLOT(allTracks())); 439 450 if (curMeta) … … void PlaybackBoxMusic::showSmartPlaylist 491 502 } 492 503 } 493 504 505 void PlaybackBoxMusic::showSearchDialog() 506 { 507 if (!playlist_popup) 508 return; 509 510 closePlaylistPopup(); 511 512 SearchDialog dialog(gContext->GetMainWindow(), "searchdialog"); 513 514 int res = dialog.ExecPopup(); 515 516 if (res > 0) 517 { 518 QString whereClause; 519 dialog.getWhereClause(whereClause); 520 updatePlaylistFromQuickPlaylist(whereClause, false); 521 } 522 } 523 494 524 void PlaybackBoxMusic::byArtist() 495 525 { 496 526 if (!playlist_popup || !curMeta) … … void PlaybackBoxMusic::byYear() 541 571 closePlaylistPopup(); 542 572 } 543 573 544 void PlaybackBoxMusic::updatePlaylistFromQuickPlaylist(QString whereClause )574 void PlaybackBoxMusic::updatePlaylistFromQuickPlaylist(QString whereClause, bool replace) 545 575 { 546 576 QValueList <int> branches_to_current_node; 547 577 548 578 visual_mode_timer->stop(); 549 579 580 if (replace) 550 581 all_playlists->getActive()->removeAllTracks(); 551 582 all_playlists->getActive()->fillSonglistFromQuery(whereClause); 552 583 all_playlists->getActive()->fillSongsFromSonglist(); -
mythplugins-0.18.1/mythmusic/
old new class PlaybackBoxMusic : public MythThem 81 81 void byGenre(); 82 82 void byYear(); 83 83 void showSmartPlaylistDialog(); 84 void showSearchDialog(); 84 85 85 86 signals: 86 87 … … class PlaybackBoxMusic : public MythThem 89 90 private: 90 91 91 92 void wireUpTheme(); 92 void updatePlaylistFromQuickPlaylist(QString whereClause );93 void updatePlaylistFromQuickPlaylist(QString whereClause, bool replace = true); 93 94 void updatePlaylistFromSmartPlaylist(QString category, QString name); 94 95 void CycleVisualizer(void); 95 96 -
mythplugins-0.18.1/mythmusic/
old new 1 #include "search.h" 2 3 #include <qlayout.h> 4 5 #include <mythtv/mythcontext.h> 6 #include <mythtv/mythdbcon.h> 7 8 SearchDialog::SearchDialog(MythMainWindow *parent, const char *name) 9 :MythPopupBox(parent, name) 10 { 11 vbox = new QVBoxLayout((QWidget *) 0, (int)(10 * hmult)); 12 QHBoxLayout *hbox = new QHBoxLayout(vbox, (int)(10 * wmult)); 13 14 // Create the widgets 15 16 // Caption 17 caption = new QLabel(QString(tr("Search Music Database")), this); 18 QFont font = caption->font(); 19 font.setPointSize(int (font.pointSize() * 1.2)); 20 font.setBold(true); 21 caption->setFont(font); 22 caption->setPaletteForegroundColor(QColor("yellow")); 23 caption->setBackgroundOrigin(ParentOrigin); 24 caption->setAlignment(Qt::AlignCenter); 25 caption->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); 26 caption->setMinimumWidth((int)(600 * hmult)); 27 caption->setMaximumWidth((int)(600 * hmult)); 28 hbox->addWidget(caption); 29 30 // LineEdit for search string 31 hbox = new QHBoxLayout(vbox, (int)(10 * hmult)); 32 searchText = new MyLineEdit(this); 33 searchText->setRW(); 34 searchText->setFocus(); 35 connect(searchText, SIGNAL(textChanged(const QString &)), 36 this, SLOT(searchTextChanged(const QString &))); 37 connect(searchText, SIGNAL(returnPressed()), 38 this, SLOT(accept())); 39 hbox->addWidget(searchText); 40 41 // Listbox for search results 42 hbox = new QHBoxLayout(vbox, (int)(5 * hmult)); 43 listbox = new MythListBox(this); 44 listbox->setScrollBar(false); 45 listbox->setBottomScrollBar(false); 46 connect(listbox, SIGNAL(accepted(int)), 47 this, SLOT(itemSelected(int))); 48 connect(this, SIGNAL(done()), 49 this, SLOT(accept())); 50 hbox->addWidget(listbox); 51 52 addLayout(vbox); 53 54 // Initially, fill list with all music 55 runQuery(""); 56 } 57 58 void SearchDialog::searchTextChanged(const QString &searchText) 59 { 60 runQuery(searchText); 61 } 62 63 void SearchDialog::runQuery(QString searchText) 64 { 65 // This method will perform a search in the 'musicmetadata' table and fill 66 // the 'listbox' widget with the results. 67 // The following columns are searched: filename, artist, album, title. 68 // To facilitate usage with a remote, two search modes exist and are enabled 69 // as follows: 70 // - If searchText contains non-digits characters, a case-insensitive 71 // substring search is done. 72 // - Otherwise, a regexp search is performed, where each digit can represent 73 // either itself or a letter as printed on some remotes -- i.e., 74 // 0 -> (0 or <space>), 1 -> 1, 2 -> (2 or a or b or c), etc. 75 76 bool substringSearch = true; 77 bool isNumber = false; 78 searchText.toULongLong(&isNumber); 79 80 char *mapping[] = { 81 "[0 ]", "1", "[2abc]", "[3def]", "[4ghi]", "[5jkl]", 82 "[6mno]", "[7pqrs]", "[8tuv]", "[9wxyz]" 83 }; 84 85 if (isNumber) { 86 // Input contains only digits. Enable digit-to-char mapping mode 87 for (int i = 0; i < 10; i++) { 88 char c = '0' + i; 89 searchText.replace(QChar(c), QString(mapping[i])); 90 } 91 substringSearch = false; 92 } 93 94 listbox->clear(); 95 96 MSqlQuery query(MSqlQuery::InitCon()); 97 98 QString queryString("SELECT filename,artist,album,title,intid " 99 "FROM musicmetadata "); 100 101 if (!searchText.isEmpty()) 102 { 103 if (substringSearch) 104 { 105 whereClause = "WHERE filename LIKE '%" + searchText + "%'" 106 " OR artist LIKE '%" + searchText + "%'" 107 " OR album LIKE '%" + searchText + "%'" 108 " OR title LIKE '%" + searchText + "%'" 109 ";"; 110 } 111 else 112 { 113 // regexp search 114 whereClause = "WHERE filename REGEXP '" + searchText + 115 "' OR artist REGEXP '" + searchText + 116 "' OR album REGEXP '" + searchText + 117 "' OR title REGEXP '" + searchText + 118 "';"; 119 } 120 } 121 122 unsigned int matchCount = 0; 123 124 queryString += whereClause; 125 126 query.prepare(queryString); 127 128 if (query.exec()) 129 { 130 if (query.isActive() && query.numRowsAffected() > 0) 131 { 132 while (query.next()) 133 { 134 // Strip path from filename 135 QString fileName(query.value(0).toString()); 136 fileName.replace(QRegExp(".*/"), ""); 137 138 // Append artist/title/album info... ok this is ugly :( 139 QString text(fileName + " [ " + 140 query.value(1).toString() + "/" + 141 query.value(2).toString() + "/" + 142 query.value(3).toString() + "]"); 143 144 // Insert item into listbox, including song identifier 145 listbox->insertItem( 146 new SearchListBoxItem(QString::fromUtf8(text), 147 query.value(4).toUInt()) 148 ); 149 150 matchCount++; 151 } 152 153 listbox->setCurrentItem(0); 154 listbox->setTopItem(0); 155 } 156 } 157 else 158 MythContext::DBError("Search music database", query); 159 160 QString captionText = 161 QString(tr("Search Music Database (%1 matches)")).arg(matchCount); 162 caption->setText(captionText); 163 } 164 165 void SearchDialog::itemSelected(int i) 166 { 167 unsigned int id = ((SearchListBoxItem*)listbox->item(i))->getId(); 168 whereClause = QString("WHERE intid='%1';").arg(id); 169 emit done(); 170 } 171 172 173 void SearchDialog::getWhereClause(QString &whereClause) 174 { 175 whereClause = this->whereClause; 176 } 177 178 SearchDialog::~SearchDialog() 179 { 180 if (vbox) 181 { 182 delete vbox; 183 vbox = NULL; 184 } 185 } -
mythplugins-0.18.1/mythmusic/
old new 1 #ifndef SEARCH_H_ 2 #define SEARCH_H_ 3 4 #include <mythtv/mythdialogs.h> 5 6 class SearchListBoxItem: public QListBoxText 7 { 8 public: 9 SearchListBoxItem(const QString &text, unsigned int id) 10 : QListBoxText(text), id(id) {}; 11 12 unsigned int getId() { return id; } 13 14 private: 15 16 unsigned int id; 17 }; 18 19 class SearchDialog: public MythPopupBox 20 { 21 Q_OBJECT 22 23 public: 24 25 SearchDialog(MythMainWindow *parent, const char *name = 0); 26 ~SearchDialog(); 27 28 void getWhereClause(QString &whereClause); 29 30 protected slots: 31 32 void searchTextChanged(const QString &searchText); 33 void itemSelected(int i); 34 35 signals: 36 37 void done(); 38 39 private: 40 41 void runQuery(QString searchText); 42 43 QVBoxLayout *vbox; 44 QLabel *caption; 45 MythListBox *listbox; 46 MythLineEdit *searchText; 47 48 QString whereClause; 49 }; 50 51 // For some reason, pressing "OK" on my Hauppauge remote does *NOT* cause the 52 // returnPressed() signal to be emitted. Hence the dirty hack below :( 53 class MyLineEdit : public MythLineEdit 54 { 55 public: 56 57 MyLineEdit(QWidget* parent) : MythLineEdit(parent) {}; 58 59 protected: 60 61 virtual void keyPressEvent( QKeyEvent *e ) 62 { 63 MythLineEdit::keyPressEvent(e); 64 if (e->key() == Qt::Key_Return) 65 emit returnPressed(); 66 } 67 }; 68 69 #endif