PageRenderTime 28ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/app/fingerprinter/MainWindow.cpp

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