| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include "PlaylistDialog.h" |
|---|
| 25 | #include "../HydrogenApp.h" |
|---|
| 26 | |
|---|
| 27 | #include <hydrogen/LocalFileMng.h> |
|---|
| 28 | #include <hydrogen/h2_exception.h> |
|---|
| 29 | #include <hydrogen/Preferences.h> |
|---|
| 30 | #include <hydrogen/hydrogen.h> |
|---|
| 31 | #include <hydrogen/playlist.h> |
|---|
| 32 | |
|---|
| 33 | #include "../widgets/Button.h" |
|---|
| 34 | |
|---|
| 35 | #include <QTreeWidget> |
|---|
| 36 | #include <QDomDocument> |
|---|
| 37 | #include <QMessageBox> |
|---|
| 38 | #include <QHeaderView> |
|---|
| 39 | #include <QFileDialog> |
|---|
| 40 | #include <vector> |
|---|
| 41 | #include <cstdlib> |
|---|
| 42 | #include <iostream> |
|---|
| 43 | #include <fstream> |
|---|
| 44 | |
|---|
| 45 | using namespace H2Core; |
|---|
| 46 | using namespace std; |
|---|
| 47 | |
|---|
| 48 | PlaylistDialog::PlaylistDialog ( QWidget* pParent ) |
|---|
| 49 | : QDialog ( pParent ) |
|---|
| 50 | , Object ( "PlayListDialog" ) |
|---|
| 51 | { |
|---|
| 52 | |
|---|
| 53 | setupUi ( this ); |
|---|
| 54 | INFOLOG ( "INIT" ); |
|---|
| 55 | setWindowTitle ( trUtf8 ( "Play List Browser" ) ); |
|---|
| 56 | setFixedSize ( width(), height() ); |
|---|
| 57 | installEventFilter(this); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | #ifdef WIN32 |
|---|
| 61 | QStringList headers; |
|---|
| 62 | headers << trUtf8 ( "Song list" ); |
|---|
| 63 | QTreeWidgetItem* header = new QTreeWidgetItem ( headers ); |
|---|
| 64 | m_pPlaylistTree->setHeaderItem ( header ); |
|---|
| 65 | m_pPlaylistTree->setAlternatingRowColors( true ); |
|---|
| 66 | |
|---|
| 67 | addSongBTN->setEnabled ( true ); |
|---|
| 68 | loadListBTN->setEnabled ( true ); |
|---|
| 69 | removeFromListBTN->setEnabled ( false ); |
|---|
| 70 | removeFromListBTN->setEnabled ( false ); |
|---|
| 71 | saveListBTN->setEnabled ( false ); |
|---|
| 72 | nodePlayBTN->setEnabled ( false ); |
|---|
| 73 | loadScriptBTN->hide(); |
|---|
| 74 | removeScriptBTN->hide(); |
|---|
| 75 | editScriptBTN->hide(); |
|---|
| 76 | newScriptBTN->hide(); |
|---|
| 77 | clearPlBTN->setEnabled ( false ); |
|---|
| 78 | |
|---|
| 79 | QVBoxLayout *sideBarLayout = new QVBoxLayout(sideBarWidget); |
|---|
| 80 | sideBarLayout->setSpacing(0); |
|---|
| 81 | sideBarLayout->setMargin(0); |
|---|
| 82 | |
|---|
| 83 | #else |
|---|
| 84 | QStringList headers; |
|---|
| 85 | headers << trUtf8 ( "Song list" ) << trUtf8 ( "Script" ) << trUtf8 ( "exec Script" ); |
|---|
| 86 | QTreeWidgetItem* header = new QTreeWidgetItem ( headers ); |
|---|
| 87 | m_pPlaylistTree->setHeaderItem ( header ); |
|---|
| 88 | m_pPlaylistTree->header()->resizeSection ( 0, 405 ); |
|---|
| 89 | m_pPlaylistTree->header()->resizeSection ( 1, 405 ); |
|---|
| 90 | m_pPlaylistTree->header()->resizeSection ( 2, 15 ); |
|---|
| 91 | m_pPlaylistTree->setAlternatingRowColors( true ); |
|---|
| 92 | |
|---|
| 93 | addSongBTN->setEnabled ( true ); |
|---|
| 94 | loadListBTN->setEnabled ( true ); |
|---|
| 95 | removeFromListBTN->setEnabled ( false ); |
|---|
| 96 | removeFromListBTN->setEnabled ( false ); |
|---|
| 97 | saveListBTN->setEnabled ( false ); |
|---|
| 98 | nodePlayBTN->setEnabled ( false ); |
|---|
| 99 | loadScriptBTN->setEnabled ( false ); |
|---|
| 100 | removeScriptBTN->setEnabled ( false ); |
|---|
| 101 | editScriptBTN->setEnabled ( false ); |
|---|
| 102 | clearPlBTN->setEnabled ( false ); |
|---|
| 103 | |
|---|
| 104 | QVBoxLayout *sideBarLayout = new QVBoxLayout(sideBarWidget); |
|---|
| 105 | sideBarLayout->setSpacing(0); |
|---|
| 106 | sideBarLayout->setMargin(0); |
|---|
| 107 | #endif |
|---|
| 108 | |
|---|
| 109 | // zoom-in btn |
|---|
| 110 | Button *up_btn = new Button( |
|---|
| 111 | NULL, |
|---|
| 112 | "/songEditor/btn_up_on.png", |
|---|
| 113 | "/songEditor/btn_up_off.png", |
|---|
| 114 | "/songEditor/btn_up_over.png", |
|---|
| 115 | QSize(18, 13) |
|---|
| 116 | ); |
|---|
| 117 | |
|---|
| 118 | up_btn->setFontSize(7); |
|---|
| 119 | up_btn->setToolTip( trUtf8( "sort" ) ); |
|---|
| 120 | connect(up_btn, SIGNAL(clicked(Button*)), this, SLOT(on_upBTN_clicked()) ); |
|---|
| 121 | sideBarLayout->addWidget(up_btn); |
|---|
| 122 | |
|---|
| 123 | // zoom-in btn |
|---|
| 124 | Button *down_btn = new Button( |
|---|
| 125 | NULL, |
|---|
| 126 | "/songEditor/btn_down_on.png", |
|---|
| 127 | "/songEditor/btn_down_off.png", |
|---|
| 128 | "/songEditor/btn_down_over.png", |
|---|
| 129 | QSize(18, 13) |
|---|
| 130 | ); |
|---|
| 131 | |
|---|
| 132 | down_btn->setFontSize(7); |
|---|
| 133 | down_btn->setToolTip( trUtf8( "sort" ) ); |
|---|
| 134 | connect(down_btn, SIGNAL(clicked(Button*)), this, SLOT(on_downBTN_clicked())); |
|---|
| 135 | sideBarLayout->addWidget(down_btn); |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | //restore the playlist |
|---|
| 139 | if( Hydrogen::get_instance()->m_PlayList.size() > 0 ){ |
|---|
| 140 | for ( uint i = 0; i < Hydrogen::get_instance()->m_PlayList.size(); ++i ){ |
|---|
| 141 | QTreeWidgetItem* m_pPlaylistItem = new QTreeWidgetItem ( m_pPlaylistTree ); |
|---|
| 142 | m_pPlaylistItem->setText ( 0, Hydrogen::get_instance()->m_PlayList[i].m_hFile ); |
|---|
| 143 | m_pPlaylistItem->setText ( 1, Hydrogen::get_instance()->m_PlayList[i].m_hScript ); |
|---|
| 144 | if ( Hydrogen::get_instance()->m_PlayList[i].m_hScriptEnabled == "Use Script" ) { |
|---|
| 145 | m_pPlaylistItem->setCheckState( 2, Qt::Checked ); |
|---|
| 146 | }else{ |
|---|
| 147 | m_pPlaylistItem->setCheckState( 2, Qt::Unchecked ); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | removeFromListBTN->setEnabled ( true ); |
|---|
| 151 | removeFromListBTN->setEnabled ( true ); |
|---|
| 152 | saveListBTN->setEnabled ( true ); |
|---|
| 153 | nodePlayBTN->setEnabled ( true ); |
|---|
| 154 | loadScriptBTN->setEnabled ( true ); |
|---|
| 155 | removeScriptBTN->setEnabled ( true ); |
|---|
| 156 | editScriptBTN->setEnabled ( true ); |
|---|
| 157 | clearPlBTN->setEnabled ( true ); |
|---|
| 158 | |
|---|
| 159 | //restore the selected item |
|---|
| 160 | int selected = Playlist::get_instance()->getActiveSongNumber(); |
|---|
| 161 | int Selected = Playlist::get_instance()->getSelectedSongNr(); |
|---|
| 162 | if( selected == -1 && Selected == -1 ) return; |
|---|
| 163 | |
|---|
| 164 | int aselected = 0; |
|---|
| 165 | if( selected == -1 ){ |
|---|
| 166 | aselected = Selected; |
|---|
| 167 | }else |
|---|
| 168 | { |
|---|
| 169 | aselected = selected ; |
|---|
| 170 | } |
|---|
| 171 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 172 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylist->topLevelItem ( aselected ); |
|---|
| 173 | m_pPlaylist->setCurrentItem ( m_pPlaylistItem ); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | QTimer *timer = new QTimer( this ); |
|---|
| 177 | connect(timer, SIGNAL(timeout() ), this, SLOT( updateActiveSongNumber() ) ); |
|---|
| 178 | timer->start( 1000 ); // update player control at 1 fps |
|---|
| 179 | |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | PlaylistDialog::~PlaylistDialog() |
|---|
| 184 | { |
|---|
| 185 | INFOLOG ( "DESTROY" ); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | void PlaylistDialog::on_addSongBTN_clicked() |
|---|
| 190 | { |
|---|
| 191 | static QString songDir = Preferences::getInstance()->getDataDirectory() + "/songs";; |
|---|
| 192 | |
|---|
| 193 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 194 | fd->setFileMode ( QFileDialog::ExistingFile ); |
|---|
| 195 | fd->setFilter ( "Hydrogen song (*.h2song)" ); |
|---|
| 196 | fd->setDirectory ( songDir ); |
|---|
| 197 | |
|---|
| 198 | fd->setWindowTitle ( trUtf8 ( "Add Song to PlayList" ) ); |
|---|
| 199 | |
|---|
| 200 | QString filename = ""; |
|---|
| 201 | if ( fd->exec() == QDialog::Accepted ){ |
|---|
| 202 | filename = fd->selectedFiles().first(); |
|---|
| 203 | updatePlayListNode ( filename ); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | void PlaylistDialog::on_removeFromListBTN_clicked() |
|---|
| 211 | { |
|---|
| 212 | |
|---|
| 213 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 214 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 215 | QTreeWidgetItem * m_pItem = m_pPlaylist->topLevelItem ( 1 ); |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | if (m_pPlaylistItem == NULL){ |
|---|
| 219 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song selected!" )); |
|---|
| 220 | return; |
|---|
| 221 | }else |
|---|
| 222 | { |
|---|
| 223 | if (m_pItem == 0){ |
|---|
| 224 | m_pPlaylist->clear(); |
|---|
| 225 | Hydrogen::get_instance()->m_PlayList.clear(); |
|---|
| 226 | Playlist::get_instance()->setSelectedSongNr( -1 ); |
|---|
| 227 | Playlist::get_instance()->setActiveSongNumber( -1 ); |
|---|
| 228 | editScriptBTN->setEnabled ( false ); |
|---|
| 229 | nodePlayBTN->setEnabled ( false ); |
|---|
| 230 | removeFromListBTN->setEnabled ( false ); |
|---|
| 231 | saveListBTN->setEnabled ( false ); |
|---|
| 232 | loadScriptBTN->setEnabled ( false ); |
|---|
| 233 | clearPlBTN->setEnabled ( false ); |
|---|
| 234 | return; |
|---|
| 235 | }else |
|---|
| 236 | { |
|---|
| 237 | ///avoid segfault if the last item will be removed!! |
|---|
| 238 | delete m_pPlaylistItem; |
|---|
| 239 | updatePlayListVector(); |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | void PlaylistDialog::on_clearPlBTN_clicked() |
|---|
| 246 | { |
|---|
| 247 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 248 | |
|---|
| 249 | m_pPlaylist->clear(); |
|---|
| 250 | Hydrogen::get_instance()->m_PlayList.clear(); |
|---|
| 251 | Playlist::get_instance()->setSelectedSongNr( -1 ); |
|---|
| 252 | Playlist::get_instance()->setActiveSongNumber( -1 ); |
|---|
| 253 | editScriptBTN->setEnabled ( false ); |
|---|
| 254 | nodePlayBTN->setEnabled ( false ); |
|---|
| 255 | removeFromListBTN->setEnabled ( false ); |
|---|
| 256 | saveListBTN->setEnabled ( false ); |
|---|
| 257 | loadScriptBTN->setEnabled ( false ); |
|---|
| 258 | clearPlBTN->setEnabled ( false ); |
|---|
| 259 | return; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | void PlaylistDialog::updatePlayListNode ( QString file ) |
|---|
| 264 | { |
|---|
| 265 | |
|---|
| 266 | QTreeWidgetItem* m_pPlaylistItem = new QTreeWidgetItem ( m_pPlaylistTree ); |
|---|
| 267 | m_pPlaylistItem->setText ( 0, file ); |
|---|
| 268 | m_pPlaylistItem->setText ( 1, "no Script" ); |
|---|
| 269 | m_pPlaylistItem->setCheckState( 2, Qt::Unchecked ); |
|---|
| 270 | |
|---|
| 271 | updatePlayListVector(); |
|---|
| 272 | loadScriptBTN->setEnabled ( true ); |
|---|
| 273 | nodePlayBTN->setEnabled ( true ); |
|---|
| 274 | removeFromListBTN->setEnabled ( true ); |
|---|
| 275 | saveListBTN->setEnabled ( true ); |
|---|
| 276 | clearPlBTN->setEnabled ( true ); |
|---|
| 277 | |
|---|
| 278 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 279 | m_pPlaylist->setCurrentItem ( m_pPlaylistItem ); |
|---|
| 280 | |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | void PlaylistDialog::on_loadListBTN_clicked() |
|---|
| 285 | { |
|---|
| 286 | |
|---|
| 287 | static QString sDirectory = Preferences::getInstance()->getDataDirectory() + "playlists/" ; |
|---|
| 288 | |
|---|
| 289 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 290 | fd->setFileMode ( QFileDialog::ExistingFile ); |
|---|
| 291 | fd->setDirectory ( sDirectory ); |
|---|
| 292 | |
|---|
| 293 | fd->setWindowTitle ( trUtf8 ( "Load Playlist" ) ); |
|---|
| 294 | |
|---|
| 295 | QString filename = ""; |
|---|
| 296 | if ( fd->exec() == QDialog::Accepted ){ |
|---|
| 297 | filename = fd->selectedFiles().first(); |
|---|
| 298 | |
|---|
| 299 | LocalFileMng fileMng; |
|---|
| 300 | int err = fileMng.loadPlayList( filename.toStdString() ); |
|---|
| 301 | if ( err != 0 ) { |
|---|
| 302 | _ERRORLOG( "Error saving the playlist" ); |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | if(Hydrogen::get_instance()->m_PlayList.size() > 0){ |
|---|
| 307 | |
|---|
| 308 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 309 | m_pPlaylist->clear(); |
|---|
| 310 | |
|---|
| 311 | for ( uint i = 0; i < Hydrogen::get_instance()->m_PlayList.size(); ++i ){ |
|---|
| 312 | QTreeWidgetItem* m_pPlaylistItem = new QTreeWidgetItem ( m_pPlaylistTree ); |
|---|
| 313 | m_pPlaylistItem->setText ( 0, Hydrogen::get_instance()->m_PlayList[i].m_hFile ); |
|---|
| 314 | m_pPlaylistItem->setText ( 1, Hydrogen::get_instance()->m_PlayList[i].m_hScript ); |
|---|
| 315 | if ( Hydrogen::get_instance()->m_PlayList[i].m_hScriptEnabled == "Use Script" ) { |
|---|
| 316 | m_pPlaylistItem->setCheckState( 2, Qt::Checked ); |
|---|
| 317 | }else{ |
|---|
| 318 | m_pPlaylistItem->setCheckState( 2, Qt::Unchecked ); |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | removeFromListBTN->setEnabled ( true ); |
|---|
| 322 | removeFromListBTN->setEnabled ( true ); |
|---|
| 323 | saveListBTN->setEnabled ( true ); |
|---|
| 324 | nodePlayBTN->setEnabled ( true ); |
|---|
| 325 | loadScriptBTN->setEnabled ( true ); |
|---|
| 326 | removeScriptBTN->setEnabled ( true ); |
|---|
| 327 | editScriptBTN->setEnabled ( true ); |
|---|
| 328 | clearPlBTN->setEnabled ( true ); |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylist->topLevelItem ( 0 ); |
|---|
| 332 | m_pPlaylist->setCurrentItem ( m_pPlaylistItem ); |
|---|
| 333 | Playlist::get_instance()->setSelectedSongNr( 0 ); |
|---|
| 334 | // Playlist::get_instance()->setNextSongByNumber( 0 ); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | } |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | void PlaylistDialog::on_newScriptBTN_clicked() |
|---|
| 342 | { |
|---|
| 343 | |
|---|
| 344 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 345 | |
|---|
| 346 | QString sDirectory = ( Preferences::getInstance()->getDataDirectory() + "scripts/"); |
|---|
| 347 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 348 | fd->setFileMode ( QFileDialog::AnyFile ); |
|---|
| 349 | fd->setFilter ( trUtf8 ( "Hydrogen Scripts (*.sh)" ) ); |
|---|
| 350 | fd->setAcceptMode ( QFileDialog::AcceptSave ); |
|---|
| 351 | fd->setWindowTitle ( trUtf8 ( "New Script" ) ); |
|---|
| 352 | fd->setDirectory ( sDirectory ); |
|---|
| 353 | |
|---|
| 354 | QString defaultFilename; |
|---|
| 355 | |
|---|
| 356 | defaultFilename += ".sh"; |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | fd->selectFile ( defaultFilename ); |
|---|
| 360 | |
|---|
| 361 | QString filename = ""; |
|---|
| 362 | if ( fd->exec() == QDialog::Accepted ) |
|---|
| 363 | { |
|---|
| 364 | filename = fd->selectedFiles().first(); |
|---|
| 365 | }else |
|---|
| 366 | { |
|---|
| 367 | return; |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | std::string name = filename.toStdString(); |
|---|
| 371 | |
|---|
| 372 | char *file; |
|---|
| 373 | file = new char[name.length() + 1]; |
|---|
| 374 | strcpy(file, name.c_str()); |
|---|
| 375 | |
|---|
| 376 | ofstream newfile; |
|---|
| 377 | newfile.open ( file ); |
|---|
| 378 | newfile << "#!/bin/sh\n\n#have phun"; |
|---|
| 379 | newfile.close(); |
|---|
| 380 | delete [] file; |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | if( pPref->getDefaultEditor() == ""){ |
|---|
| 384 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Default Editor Set. Please set your Default Editor\nDo not use a console based Editor\nSorry, but this will not work for the moment." ) ); |
|---|
| 385 | |
|---|
| 386 | static QString lastUsedDir = "/usr/bin/"; |
|---|
| 387 | |
|---|
| 388 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 389 | fd->setFileMode ( QFileDialog::ExistingFile ); |
|---|
| 390 | fd->setDirectory ( lastUsedDir ); |
|---|
| 391 | |
|---|
| 392 | fd->setWindowTitle ( trUtf8 ( "Set your Default Editor" ) ); |
|---|
| 393 | |
|---|
| 394 | QString filename = ""; |
|---|
| 395 | if ( fd->exec() == QDialog::Accepted ){ |
|---|
| 396 | filename = fd->selectedFiles().first(); |
|---|
| 397 | |
|---|
| 398 | pPref->setDefaultEditor( filename ); |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | std::string openfile = pPref->getDefaultEditor().toStdString() + " " + filename.toStdString() + "&"; |
|---|
| 403 | |
|---|
| 404 | char *ofile; |
|---|
| 405 | ofile = new char[openfile.length() + 1]; |
|---|
| 406 | strcpy(ofile, openfile.c_str()); |
|---|
| 407 | std::system( ofile ); |
|---|
| 408 | delete [] ofile; |
|---|
| 409 | return; |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | void PlaylistDialog::on_saveListBTN_clicked() |
|---|
| 416 | { |
|---|
| 417 | |
|---|
| 418 | QString sDirectory = Preferences::getInstance()->getDataDirectory() + "playlists/"; |
|---|
| 419 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 420 | fd->setFileMode ( QFileDialog::AnyFile ); |
|---|
| 421 | fd->setFilter ( trUtf8 ( "Hydrogen Playlist (*.h2playlist)" ) ); |
|---|
| 422 | fd->setAcceptMode ( QFileDialog::AcceptSave ); |
|---|
| 423 | fd->setWindowTitle ( trUtf8 ( "Save Playlist" ) ); |
|---|
| 424 | fd->setDirectory ( sDirectory ); |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | QString defaultFilename; |
|---|
| 428 | |
|---|
| 429 | defaultFilename += ".h2playlist"; |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | fd->selectFile ( defaultFilename ); |
|---|
| 433 | |
|---|
| 434 | QString filename = ""; |
|---|
| 435 | if ( fd->exec() == QDialog::Accepted ) |
|---|
| 436 | { |
|---|
| 437 | filename = fd->selectedFiles().first(); |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | LocalFileMng fileMng; |
|---|
| 441 | int err = fileMng.savePlayList( filename.toStdString() ); |
|---|
| 442 | if ( err != 0 ) { |
|---|
| 443 | _ERRORLOG( "Error saving the playlist" ); |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | void PlaylistDialog::on_loadScriptBTN_clicked() |
|---|
| 449 | { |
|---|
| 450 | |
|---|
| 451 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 452 | if ( m_pPlaylistItem == NULL ){ |
|---|
| 453 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song in List or no Song selected!" ) ); |
|---|
| 454 | return; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | static QString lastUsedDir = Preferences::getInstance()->getDataDirectory() + "scripts/"; |
|---|
| 458 | |
|---|
| 459 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 460 | fd->setFileMode ( QFileDialog::ExistingFile ); |
|---|
| 461 | fd->setDirectory ( lastUsedDir ); |
|---|
| 462 | fd->setFilter ( trUtf8 ( "Hydrogen Playlist (*.sh)" ) ); |
|---|
| 463 | fd->setWindowTitle ( trUtf8 ( "Add Script to selected Song" ) ); |
|---|
| 464 | |
|---|
| 465 | QString filename = ""; |
|---|
| 466 | if ( fd->exec() == QDialog::Accepted ){ |
|---|
| 467 | filename = fd->selectedFiles().first(); |
|---|
| 468 | |
|---|
| 469 | std::string filetest = filename.toStdString(); |
|---|
| 470 | int error = filetest.rfind(" "); |
|---|
| 471 | if(error >= 0){ |
|---|
| 472 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "Script name or path to the script contains whitespaces.\nIMPORTANT\nThe path to the script and the scriptname must without whitespaces.") ); |
|---|
| 473 | return; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | m_pPlaylistItem->setText ( 1, filename ); |
|---|
| 477 | editScriptBTN->setEnabled ( true ); |
|---|
| 478 | removeScriptBTN->setEnabled ( true ); |
|---|
| 479 | updatePlayListVector(); |
|---|
| 480 | |
|---|
| 481 | } |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | void PlaylistDialog::on_removeScriptBTN_clicked() |
|---|
| 486 | { |
|---|
| 487 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | if (m_pPlaylistItem == NULL){ |
|---|
| 491 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song selected!" )); |
|---|
| 492 | return; |
|---|
| 493 | }else{ |
|---|
| 494 | QString selected = ""; |
|---|
| 495 | selected = m_pPlaylistItem->text ( 1 ); |
|---|
| 496 | if( selected == "no Script"){ |
|---|
| 497 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Script in use!" )); |
|---|
| 498 | return; |
|---|
| 499 | }else |
|---|
| 500 | { |
|---|
| 501 | m_pPlaylistItem->setText ( 1, "no Script" ); |
|---|
| 502 | m_pPlaylistItem->setCheckState( 2, Qt::Unchecked ); |
|---|
| 503 | updatePlayListVector(); |
|---|
| 504 | } |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | void PlaylistDialog::on_editScriptBTN_clicked() |
|---|
| 511 | { |
|---|
| 512 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 513 | if( pPref->getDefaultEditor() == ""){ |
|---|
| 514 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Default Editor Set. Please set your Default Editor\nDo not use a console based Editor\nSorry, but this will not work for the moment." ) ); |
|---|
| 515 | |
|---|
| 516 | static QString lastUsedDir = "/usr/bin/"; |
|---|
| 517 | |
|---|
| 518 | QFileDialog *fd = new QFileDialog ( this ); |
|---|
| 519 | fd->setFileMode ( QFileDialog::ExistingFile ); |
|---|
| 520 | fd->setDirectory ( lastUsedDir ); |
|---|
| 521 | |
|---|
| 522 | fd->setWindowTitle ( trUtf8 ( "Set your Default Editor" ) ); |
|---|
| 523 | |
|---|
| 524 | QString filename = ""; |
|---|
| 525 | if ( fd->exec() == QDialog::Accepted ){ |
|---|
| 526 | filename = fd->selectedFiles().first(); |
|---|
| 527 | |
|---|
| 528 | pPref->setDefaultEditor( filename ); |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 533 | |
|---|
| 534 | if ( m_pPlaylistItem == NULL ){ |
|---|
| 535 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song selected!" ) ); |
|---|
| 536 | return; |
|---|
| 537 | } |
|---|
| 538 | QString selected = ""; |
|---|
| 539 | selected = m_pPlaylistItem->text ( 1 ); |
|---|
| 540 | |
|---|
| 541 | std::string filename = pPref->getDefaultEditor().toStdString() + " " + selected.toStdString() + "&"; |
|---|
| 542 | |
|---|
| 543 | if( selected == "no Script"){ |
|---|
| 544 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Script selected!" )); |
|---|
| 545 | return; |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | char *file; |
|---|
| 549 | file = new char[ filename.length() + 1 ]; |
|---|
| 550 | strcpy( file , filename.c_str() ); |
|---|
| 551 | std::system( file ); |
|---|
| 552 | delete [] file; |
|---|
| 553 | return; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | void PlaylistDialog::on_upBTN_clicked() |
|---|
| 558 | { |
|---|
| 559 | |
|---|
| 560 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 561 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 562 | int index = m_pPlaylist->indexOfTopLevelItem ( m_pPlaylistItem ); |
|---|
| 563 | |
|---|
| 564 | if (index == 0 ) return; |
|---|
| 565 | |
|---|
| 566 | QTreeWidgetItem* tmpPlaylistItem = m_pPlaylist->takeTopLevelItem ( index ); |
|---|
| 567 | |
|---|
| 568 | m_pPlaylist->insertTopLevelItem ( index -1, tmpPlaylistItem ); |
|---|
| 569 | m_pPlaylist->setCurrentItem ( tmpPlaylistItem ); |
|---|
| 570 | updatePlayListVector(); |
|---|
| 571 | |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | void PlaylistDialog::on_downBTN_clicked() |
|---|
| 576 | { |
|---|
| 577 | |
|---|
| 578 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 579 | int length = m_pPlaylist->topLevelItemCount(); |
|---|
| 580 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 581 | int index = m_pPlaylist->indexOfTopLevelItem ( m_pPlaylistItem ); |
|---|
| 582 | |
|---|
| 583 | if ( index == length - 1) |
|---|
| 584 | return; |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | QTreeWidgetItem* tmpPlaylistItem = m_pPlaylist->takeTopLevelItem ( index ); |
|---|
| 588 | |
|---|
| 589 | m_pPlaylist->insertTopLevelItem ( index +1, tmpPlaylistItem ); |
|---|
| 590 | m_pPlaylist->setCurrentItem ( tmpPlaylistItem ); |
|---|
| 591 | updatePlayListVector(); |
|---|
| 592 | |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | void PlaylistDialog::on_m_pPlaylistTree_itemClicked ( QTreeWidgetItem * item, int column ) |
|---|
| 597 | { |
|---|
| 598 | if ( column == 2 ){ |
|---|
| 599 | QString selected = ""; |
|---|
| 600 | selected = item->text ( 1 ); |
|---|
| 601 | |
|---|
| 602 | if( selected == "no Script"){ |
|---|
| 603 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Script!" )); |
|---|
| 604 | item->setCheckState( 2, Qt::Unchecked ); |
|---|
| 605 | return; |
|---|
| 606 | } |
|---|
| 607 | updatePlayListVector(); |
|---|
| 608 | } |
|---|
| 609 | return; |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | void PlaylistDialog::on_nodePlayBTN_clicked() |
|---|
| 614 | { |
|---|
| 615 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 616 | if ( m_pPlaylistItem == NULL ){ |
|---|
| 617 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song selected!" ) ); |
|---|
| 618 | return; |
|---|
| 619 | } |
|---|
| 620 | QString selected = ""; |
|---|
| 621 | selected = m_pPlaylistItem->text ( 0 ); |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | HydrogenApp *pH2App = HydrogenApp::getInstance(); |
|---|
| 625 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | if ( engine->getState() == STATE_PLAYING ){ |
|---|
| 629 | engine->sequencer_stop(); |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | LocalFileMng mng; |
|---|
| 633 | Song *pSong = Song::load ( selected ); |
|---|
| 634 | if ( pSong == NULL ){ |
|---|
| 635 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "Error loading song." ) ); |
|---|
| 636 | return; |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | pH2App->setSong ( pSong ); |
|---|
| 640 | engine->setSelectedPatternNumber ( 0 ); |
|---|
| 641 | |
|---|
| 642 | Hydrogen::get_instance()->sequencer_play(); |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | void PlaylistDialog::on_nodeStopBTN_clicked() |
|---|
| 647 | { |
|---|
| 648 | Hydrogen::get_instance()->sequencer_stop(); |
|---|
| 649 | Hydrogen::get_instance()->setPatternPos ( 0 ); |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | void PlaylistDialog::on_m_pPlaylistTree_itemDoubleClicked () |
|---|
| 654 | { |
|---|
| 655 | |
|---|
| 656 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylistTree->currentItem(); |
|---|
| 657 | if ( m_pPlaylistItem == NULL ){ |
|---|
| 658 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Song selected!" ) ); |
|---|
| 659 | return; |
|---|
| 660 | } |
|---|
| 661 | QString selected = ""; |
|---|
| 662 | selected = m_pPlaylistItem->text ( 0 ); |
|---|
| 663 | |
|---|
| 664 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 665 | int index = m_pPlaylist->indexOfTopLevelItem ( m_pPlaylistItem ); |
|---|
| 666 | Playlist::get_instance()->setSelectedSongNr( index ); |
|---|
| 667 | Playlist::get_instance()->setActiveSongNumber( index ); |
|---|
| 668 | |
|---|
| 669 | HydrogenApp *pH2App = HydrogenApp::getInstance(); |
|---|
| 670 | Hydrogen *engine = Hydrogen::get_instance(); |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | if ( engine->getState() == STATE_PLAYING ){ |
|---|
| 674 | engine->sequencer_stop(); |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | LocalFileMng mng; |
|---|
| 678 | Song *pSong = Song::load ( selected ); |
|---|
| 679 | if ( pSong == NULL ){ |
|---|
| 680 | QMessageBox::information ( this, "Hydrogen", trUtf8 ( "Error loading song." ) ); |
|---|
| 681 | return; |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | pH2App->setSong ( pSong ); |
|---|
| 685 | engine->setSelectedPatternNumber ( 0 ); |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | pH2App->setStatusBarMessage( trUtf8( "Playlist: Set song No. %1" ).arg( index +1 ), 5000 ); |
|---|
| 689 | |
|---|
| 690 | ///exec script |
|---|
| 691 | ///this is very very simple and only an experiment |
|---|
| 692 | #ifdef WIN32 |
|---|
| 693 | //I know nothing about windows scripts -wolke- |
|---|
| 694 | return; |
|---|
| 695 | #else |
|---|
| 696 | QString execscript = ""; |
|---|
| 697 | selected = m_pPlaylistItem->text ( 1 ); |
|---|
| 698 | bool execcheckbox = m_pPlaylistItem->checkState ( 2 ); |
|---|
| 699 | std::string filename = selected.toStdString(); |
|---|
| 700 | |
|---|
| 701 | if( execcheckbox == false){ |
|---|
| 702 | //QMessageBox::information ( this, "Hydrogen", trUtf8 ( "No Script selected!" )); |
|---|
| 703 | return; |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | if( execscript == "Script not used"){ |
|---|
| 707 | //QMessageBox::information ( this, "Hydrogen", trUtf8 ( "Script not in use!" )); |
|---|
| 708 | return; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | char *file; |
|---|
| 712 | file = new char[ filename.length() + 1 ]; |
|---|
| 713 | strcpy( file , filename.c_str() ); |
|---|
| 714 | std::system( file ); |
|---|
| 715 | delete [] file; |
|---|
| 716 | return; |
|---|
| 717 | #endif |
|---|
| 718 | |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | void PlaylistDialog::updatePlayListVector() |
|---|
| 723 | { |
|---|
| 724 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 725 | int length = m_pPlaylist->topLevelItemCount(); |
|---|
| 726 | |
|---|
| 727 | Hydrogen::get_instance()->m_PlayList.clear(); |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | for (int i = 0 ;i < length; i++){ |
|---|
| 732 | QTreeWidgetItem * m_pPlaylistItem = m_pPlaylist->topLevelItem ( i ); |
|---|
| 733 | |
|---|
| 734 | QString execval = ""; |
|---|
| 735 | bool execcheckbox = m_pPlaylistItem->checkState ( 2 ); |
|---|
| 736 | if ( execcheckbox == true ) { |
|---|
| 737 | execval = "Use Script"; |
|---|
| 738 | }else{ |
|---|
| 739 | execval = "Script not used"; |
|---|
| 740 | } |
|---|
| 741 | Hydrogen::HPlayListNode playListItem; |
|---|
| 742 | playListItem.m_hFile = m_pPlaylistItem->text ( 0 ); |
|---|
| 743 | playListItem.m_hScript = m_pPlaylistItem->text ( 1 ); |
|---|
| 744 | playListItem.m_hScriptEnabled = execval; |
|---|
| 745 | |
|---|
| 746 | Hydrogen::get_instance()->m_PlayList.push_back( playListItem ); |
|---|
| 747 | } |
|---|
| 748 | } |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | void PlaylistDialog::updateActiveSongNumber() |
|---|
| 752 | { |
|---|
| 753 | int selected = Playlist::get_instance()->getActiveSongNumber(); |
|---|
| 754 | if ( selected == -1 ) |
|---|
| 755 | return; |
|---|
| 756 | |
|---|
| 757 | QTreeWidget* m_pPlaylist = m_pPlaylistTree; |
|---|
| 758 | QTreeWidgetItem* m_pPlaylistItem = m_pPlaylist->topLevelItem ( selected ); |
|---|
| 759 | m_pPlaylist->setCurrentItem ( m_pPlaylistItem ); |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | bool PlaylistDialog::eventFilter ( QObject *o, QEvent *e ) |
|---|
| 764 | { |
|---|
| 765 | |
|---|
| 766 | UNUSED ( o ); |
|---|
| 767 | if ( e->type() == QEvent::KeyPress ) |
|---|
| 768 | { |
|---|
| 769 | QKeyEvent *k = ( QKeyEvent * ) e; |
|---|
| 770 | |
|---|
| 771 | switch ( k->key() ) |
|---|
| 772 | { |
|---|
| 773 | case Qt::Key_F5 : |
|---|
| 774 | if( Hydrogen::get_instance()->m_PlayList.size() == 0) |
|---|
| 775 | break; |
|---|
| 776 | Playlist::get_instance()->setPrevSongPlaylist(); |
|---|
| 777 | return TRUE; |
|---|
| 778 | break; |
|---|
| 779 | |
|---|
| 780 | case Qt::Key_F6 : |
|---|
| 781 | if( Hydrogen::get_instance()->m_PlayList.size() == 0) |
|---|
| 782 | break; |
|---|
| 783 | Playlist::get_instance()->setNextSongPlaylist(); |
|---|
| 784 | return TRUE; |
|---|
| 785 | break; |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | } |
|---|
| 789 | else |
|---|
| 790 | { |
|---|
| 791 | return FALSE; // standard event processing |
|---|
| 792 | } |
|---|
| 793 | |
|---|
| 794 | return NULL; |
|---|
| 795 | } |
|---|
| 796 | |
|---|