Changeset 124 for smplayer/trunk/src/favorites.cpp
- Timestamp:
- Mar 16, 2012, 4:02:47 PM (13 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 121-122
- Property svn:mergeinfo changed
-
smplayer/trunk/src/favorites.cpp
r119 r124 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 1 Ricardo Villalba <rvm@escomposlinux.org>2 Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 20 20 #include "favoriteeditor.h" 21 21 22 #include <QMenu>23 22 #include <QAction> 24 23 #include <QSettings> … … 26 25 #include <QTextStream> 27 26 #include <QInputDialog> 28 29 //#define FIRST_MENU_ENTRY 3 30 #define FIRST_MENU_ENTRY 2 31 32 Favorites::Favorites(QString filename, QWidget * parent) : QObject(parent) 27 #include <QFileInfo> 28 29 //#define FIRST_MENU_ENTRY 4 30 #define FIRST_MENU_ENTRY 3 31 32 Favorites::Favorites(QString filename, QWidget * parent) : QMenu(parent) 33 33 { 34 34 _filename = filename; 35 _menu = 0;36 35 37 36 parent_widget = parent; … … 52 51 connect(previous_act, SIGNAL(triggered()), this, SLOT(previous())); 53 52 53 add_current_act = new QAction( "Add current media", this); 54 add_current_act->setEnabled(false); 55 connect(add_current_act, SIGNAL(triggered()), SLOT(addCurrentPlaying())); 56 57 retranslateStrings(); 58 54 59 load(); 60 61 connect( this, SIGNAL(triggered(QAction *)), 62 this, SLOT(triggered_slot(QAction *)) ); 63 64 addAction(edit_act); 65 addAction(add_current_act); 66 //addAction(jump_act); 67 addSeparator(); 68 69 populateMenu(); 70 55 71 } 56 72 57 73 Favorites::~Favorites() { 74 /* qDebug("Favorites::~Favorites"); */ 75 58 76 save(); 59 if (_menu != 0) delete _menu; 60 } 61 62 QMenu * Favorites::menu() { 63 if (_menu == 0) createMenu(); 64 return _menu; 65 } 66 67 void Favorites::createMenu() { 68 _menu = new QMenu(parent_widget); 69 connect( _menu, SIGNAL(triggered(QAction *)), 70 this, SLOT(triggered_slot(QAction *)) ); 71 72 _menu->addAction(edit_act); 73 //_menu->addAction(jump_act); 74 _menu->addSeparator(); 75 76 populateMenu(); 77 delete_children(); 78 } 79 80 void Favorites::delete_children() { 81 for (int n=0; n < child.count(); n++) { 82 if (child[n]) delete child[n]; 83 child[n] = 0; 84 } 85 child.clear(); 86 } 87 88 void Favorites::retranslateStrings() { 89 edit_act->setText( tr("&Edit...") ); 90 jump_act->setText( tr("&Jump...") ); 91 next_act->setText( tr("&Next") ); 92 previous_act->setText( tr("&Previous") ); 93 add_current_act->setText( tr("&Add current media") ); 94 } 95 96 Favorites * Favorites::createNewObject(QString filename, QWidget * parent) { 97 return new Favorites(filename, parent); 77 98 } 78 99 … … 81 102 QString i = QString::number(n+1); 82 103 QString name = QString("%1 - " + f_list[n].name() ).arg( i.insert( i.size()-1, '&' ), 3, ' ' ); 83 QAction * a = _menu->addAction( name ); 84 a->setData( f_list[n].file() ); 85 a->setIcon( QIcon( f_list[n].icon() ) ); 86 a->setStatusTip( f_list[n].file() ); 104 if (f_list[n].isSubentry()) { 105 Favorites * new_fav = createNewObject(f_list[n].file(), parent_widget); 106 new_fav->getCurrentMedia(received_file_playing, received_title); 107 connect(this, SIGNAL(sendCurrentMedia(const QString &, const QString &)), 108 new_fav, SLOT(getCurrentMedia(const QString &, const QString &))); 109 /* 110 new_fav->editAct()->setText( editAct()->text() ); 111 new_fav->jumpAct()->setText( jumpAct()->text() ); 112 new_fav->nextAct()->setText( nextAct()->text() ); 113 new_fav->previousAct()->setText( previousAct()->text() ); 114 new_fav->addCurrentAct()->setText( addCurrentAct()->text() ); 115 */ 116 117 child.push_back(new_fav); 118 119 QAction * a = addMenu( new_fav ); 120 a->setText( name ); 121 a->setIcon( QIcon( f_list[n].icon() ) ); 122 } else { 123 QAction * a = addAction( name ); 124 a->setData( f_list[n].file() ); 125 a->setIcon( QIcon( f_list[n].icon() ) ); 126 a->setStatusTip( f_list[n].file() ); 127 } 87 128 } 88 129 } … … 90 131 void Favorites::updateMenu() { 91 132 // Remove all except the first 2 items 92 while ( _menu->actions().count() > FIRST_MENU_ENTRY) {93 QAction * a = _menu->actions()[FIRST_MENU_ENTRY];94 _menu->removeAction( a );133 while (actions().count() > FIRST_MENU_ENTRY) { 134 QAction * a = actions()[FIRST_MENU_ENTRY]; 135 removeAction( a ); 95 136 a->deleteLater(); 96 137 } 138 139 delete_children(); 97 140 98 141 populateMenu(); … … 110 153 111 154 void Favorites::markCurrent() { 112 for (int n = FIRST_MENU_ENTRY; n < _menu->actions().count(); n++) {113 QAction * a = _menu->actions()[n];155 for (int n = FIRST_MENU_ENTRY; n < actions().count(); n++) { 156 QAction * a = actions()[n]; 114 157 QString file = a->data().toString(); 115 158 QFont f = a->font(); 116 159 117 if ( file == current_file) {160 if ((!file.isEmpty()) && (file == current_file)) { 118 161 f.setBold(true); 119 162 a->setFont( f ); … … 136 179 137 180 int current = findFile(current_file); 138 //if (current < 0) current = 0; 139 140 current++; 141 if (current >= f_list.count()) current = 0; 142 143 QAction * a = _menu->actions()[current+FIRST_MENU_ENTRY]; // Skip "edit" and separator 181 182 int i = current; 183 if (current < 0) current = 0; 184 185 do { 186 i++; 187 if (i == current) break; 188 if (i >= f_list.count()) i = 0; 189 } while (f_list[i].isSubentry()); 190 191 QAction * a = actions()[i+FIRST_MENU_ENTRY]; // Skip "edit" and separator 144 192 if (a != 0) { 145 193 a->trigger(); … … 151 199 152 200 int current = findFile(current_file); 153 //if (current < 0) current = 0; 154 155 current--; 156 if (current < 0) current = f_list.count()-1; 157 158 QAction * a = _menu->actions()[current+FIRST_MENU_ENTRY]; // Skip "edit" and separator 201 202 int i = current; 203 if (current < 0) current = 0; 204 205 do { 206 i--; 207 if (i == current) break; 208 if (i < 0) i = f_list.count()-1; 209 } while (f_list[i].isSubentry()); 210 211 QAction * a = actions()[i+FIRST_MENU_ENTRY]; // Skip "edit" and separator 159 212 if (a != 0) { 160 213 a->trigger(); 214 } 215 } 216 217 void Favorites::getCurrentMedia(const QString & filename, const QString & title) { 218 qDebug("Favorites::getCurrentMedia: '%s', '%s'", filename.toUtf8().constData(), title.toUtf8().constData()); 219 220 if (!filename.isEmpty()) { 221 received_file_playing = filename; 222 received_title = title; 223 224 emit sendCurrentMedia(filename, title); 225 226 add_current_act->setEnabled(true); 227 } 228 } 229 230 void Favorites::addCurrentPlaying() { 231 if (received_file_playing.isEmpty()) { 232 qDebug("Favorites::addCurrentPlaying: received file is empty, doing nothing"); 233 } else { 234 Favorite fav; 235 fav.setName(received_title); 236 fav.setFile(received_file_playing); 237 f_list.append(fav); 238 save(); 239 updateMenu(); 161 240 } 162 241 } … … 174 253 stream << "#EXTINF:0,"; 175 254 stream << f_list[n].name() << ","; 176 stream << f_list[n].icon() << "\n"; 255 stream << f_list[n].icon() << ","; 256 stream << f_list[n].isSubentry() << "\n"; 177 257 stream << f_list[n].file() << "\n"; 178 258 } … … 185 265 186 266 QRegExp m3u_id("^#EXTM3U|^#M3U"); 187 QRegExp info("^#EXTINF:(.*),(.*),(.*)"); 267 QRegExp info1("^#EXTINF:(.*),(.*),(.*)"); 268 QRegExp info2("^#EXTINF:(.*),(.*),(.*),(.*)"); 188 269 189 270 QFile f( _filename ); … … 200 281 while ( !stream.atEnd() ) { 201 282 line = stream.readLine(); // line of text excluding '\n' 283 //qDebug("info2.indexIn: %d", info2.indexIn(line)); 284 //qDebug("info1.indexIn: %d", info1.indexIn(line)); 202 285 //qDebug( " * line: '%s'", line.toUtf8().data() ); 203 286 if (m3u_id.indexIn(line)!=-1) { … … 206 289 } 207 290 else 208 if (info.indexIn(line) != -1) { 209 fav.setName( info.cap(2) ); 210 fav.setIcon( info.cap(3) ); 291 if (info2.indexIn(line) != -1) { 292 fav.setName( info2.cap(2) ); 293 fav.setIcon( info2.cap(3) ); 294 fav.setSubentry( info2.cap(4).toInt() == 1 ); 295 } 296 else 297 // Compatibility with old files 298 if (info1.indexIn(line) != -1) { 299 fav.setName( info1.cap(2) ); 300 fav.setIcon( info1.cap(3) ); 301 fav.setSubentry( false ); 211 302 } 212 303 else … … 224 315 fav.setFile(""); 225 316 fav.setIcon(""); 317 fav.setSubentry(false); 226 318 } 227 319 } … … 236 328 237 329 e.setData(f_list); 330 e.setStorePath( QFileInfo(_filename).absolutePath() ); 238 331 239 332 if (e.exec() == QDialog::Accepted) { 240 333 f_list = e.data(); 334 save(); 241 335 updateMenu(); 242 336 /* … … 258 352 last_item = item; 259 353 item--; 260 _menu->actions()[item+FIRST_MENU_ENTRY]->trigger(); 354 actions()[item+FIRST_MENU_ENTRY]->trigger(); 355 } 356 } 357 358 // Language change stuff 359 void Favorites::changeEvent(QEvent *e) { 360 if (e->type() == QEvent::LanguageChange) { 361 retranslateStrings(); 362 } else { 363 QWidget::changeEvent(e); 261 364 } 262 365 }
Note:
See TracChangeset
for help on using the changeset viewer.