PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/fingerprinter/MainWindow.cpp

https://github.com/RJ/lastfm-desktop
C++ | 149 lines | 99 code | 31 blank | 19 comment | 3 complexity | f0077d26e5edc92273e8ba90ec9045b0 MD5 | raw file
Possible License(s): GPL-2.0
  1. /***************************************************************************
  2. * Copyright 2005-2009 Last.fm Ltd. *
  3. * *
  4. * This program is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include "MainWindow.h"
  20. #include "Settings.h"
  21. #include "lib/unicorn/widgets/AboutDialog.h"
  22. #include <QUrl>
  23. #include <QDebug>
  24. #include <QDesktopServices>
  25. #include "_version.h"
  26. MainWindow::MainWindow()
  27. {
  28. ui.setupUi( this );
  29. setWindowTitle( tr( "Last.fm Fingerprinter" ) );
  30. setStatusBar( 0 );
  31. setAcceptDrops(true);
  32. resize( Settings().size() );
  33. move( Settings().position() );
  34. #ifndef Q_WS_MAC
  35. QMenu* fileMenu = new QMenu( tr( "&File" ), this );
  36. QAction* exitAction = fileMenu->addAction( tr( "E&xit" ), this, SLOT( close() ) );
  37. #ifdef Q_WS_X11
  38. exitAction->setShortcut( tr( "CTRL+Q" ) );
  39. exitAction->setText( tr("&Quit") );
  40. #endif
  41. menuBar()->insertMenu( menuBar()->actions().at( 0 ), fileMenu );
  42. #endif
  43. // Help shortcut
  44. #ifdef Q_WS_MAC
  45. ui.actionFAQ->setShortcut( tr( "Ctrl+?" ) );
  46. #else
  47. ui.actionFAQ->setShortcut( tr( "F1") );
  48. #endif
  49. QString info = tr(
  50. "<ol>"
  51. "<li>Select the folders containing the tracks that you wish to fingerprint."
  52. "<li>Press the Fingerprint button at the bottom to start."
  53. "</ol>"
  54. "This operation will not modify your files in any way, it will only analyse them "
  55. "and post a unique ID (fingerprint) to Last.fm."
  56. "<p>Please note that you can stop at any time; the app will remember how far it got, "
  57. "and automatically resume from that point the next time." );
  58. ui.informationLabel->setText( info );
  59. connect( ui.actionFAQ, SIGNAL( triggered() ),
  60. this, SLOT( showFAQ() ) );
  61. connect( ui.actionAbout, SIGNAL( triggered() ),
  62. this, SLOT( aboutDialog() ) );
  63. connect( ui.actionLogout, SIGNAL( triggered() ),
  64. this, SIGNAL( logout() ) );
  65. connect( ui.fingerprintButton, SIGNAL( clicked() ),
  66. this, SLOT( fingerprintButtonClicked() ) );
  67. }
  68. void
  69. MainWindow::start()
  70. {
  71. show();
  72. ui.dirTree->init();
  73. }
  74. void
  75. MainWindow::closeEvent( QCloseEvent *event )
  76. {
  77. emit wantsToClose( event );
  78. }
  79. void
  80. MainWindow::fingerprintButtonClicked()
  81. {
  82. emit startFingerprinting( ui.dirTree->getInclusions() );
  83. }
  84. void
  85. MainWindow::dragEnterEvent (QDragEnterEvent* event)
  86. {
  87. if (event->mimeData()->hasFormat("text/plain"))
  88. event->acceptProposedAction();
  89. }
  90. void
  91. MainWindow::dropEvent (QDropEvent* event)
  92. {
  93. QStringList files = QUrl::fromEncoded(event->mimeData()->text().toAscii()).toString().split( "\n", QString::SkipEmptyParts );
  94. foreach( QString file, files )
  95. {
  96. if (!file.startsWith( "file://" ))
  97. continue;
  98. file.remove(file.size()-1,1);
  99. file.remove(0,7);
  100. QFileInfo fileinfo( file );
  101. QString path = fileinfo.absoluteFilePath();
  102. if ( !fileinfo.isDir() )
  103. path = fileinfo.absolutePath();
  104. ui.dirTree->checkPath( path, Qt::Checked );
  105. ui.dirTree->expandPath( path );
  106. ui.dirTree->showPath( path, QAbstractItemView::PositionAtCenter );
  107. }
  108. }
  109. void
  110. MainWindow::showFAQ()
  111. {
  112. QDesktopServices::openUrl( QUrl("http://www.last.fm/help/faq/?category=Fingerprinting") );
  113. }
  114. void
  115. MainWindow::aboutDialog()
  116. {
  117. AboutDialog( this ).exec();
  118. }