PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/qmmp/src/qmmpui/detailsdialog.cpp

http://qmmp.googlecode.com/
C++ | 178 lines | 144 code | 11 blank | 23 comment | 24 complexity | f689180b03b08fc137524c1b92bc6536 MD5 | raw file
Possible License(s): GPL-2.0
  1. /***************************************************************************
  2. * Copyright (C) 2009-2012 by Ilya Kotov *
  3. * forkotov02@hotmail.ru *
  4. * *
  5. * This program 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 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  19. ***************************************************************************/
  20. #include <QDesktopServices>
  21. #include <QTextCodec>
  22. #include <QDir>
  23. #include <QFile>
  24. #include <QFileInfo>
  25. #include <QProcess>
  26. #include <qmmp/metadatamanager.h>
  27. #include <qmmp/metadatamodel.h>
  28. #include <qmmp/tagmodel.h>
  29. #include <qmmp/soundcore.h>
  30. #include "ui_detailsdialog.h"
  31. #include "playlistitem.h"
  32. #include "tageditor_p.h"
  33. #include "detailsdialog.h"
  34. DetailsDialog::DetailsDialog(PlayListItem *item, QWidget *parent)
  35. : QDialog(parent)
  36. {
  37. m_ui = new Ui::DetailsDialog;
  38. setAttribute(Qt::WA_QuitOnClose, false);
  39. setAttribute(Qt::WA_DeleteOnClose, false);
  40. m_metaDataModel = 0;
  41. m_item = item;
  42. m_ui->setupUi(this);
  43. setAttribute(Qt::WA_DeleteOnClose);
  44. m_path = item->url();
  45. setWindowTitle (m_path.section('/',-1));
  46. m_ui->pathEdit->setText(m_path);
  47. m_ui->directoryButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon));
  48. m_metaDataModel = MetaDataManager::instance()->createMetaDataModel(item->url(), this);
  49. if(m_metaDataModel)
  50. {
  51. foreach(TagModel *tagModel, m_metaDataModel->tags())
  52. m_ui->tabWidget->addTab(new TagEditor(tagModel, this), tagModel->name());
  53. foreach(QString title, m_metaDataModel->descriptions().keys())
  54. {
  55. QTextEdit *textEdit = new QTextEdit(this);
  56. textEdit->setReadOnly(true);
  57. textEdit->setPlainText(m_metaDataModel->descriptions().value(title));
  58. m_ui->tabWidget->addTab(textEdit, title);
  59. }
  60. }
  61. printInfo();
  62. }
  63. DetailsDialog::~DetailsDialog()
  64. {
  65. delete m_ui;
  66. }
  67. void DetailsDialog:: on_directoryButton_clicked()
  68. {
  69. QString dir_path;
  70. if(!m_path.contains("://")) //local file
  71. dir_path = QFileInfo(m_path).absolutePath();
  72. else if (m_path.contains(":///")) //pseudo-protocol
  73. {
  74. dir_path = QUrl(m_path).path();
  75. dir_path.replace(QString(QUrl::toPercentEncoding("#")), "#");
  76. dir_path.replace(QString(QUrl::toPercentEncoding("?")), "?");
  77. dir_path.replace(QString(QUrl::toPercentEncoding("%")), "%");
  78. dir_path = QFileInfo(dir_path).absolutePath();
  79. }
  80. else
  81. return;
  82. #ifdef Q_WS_X11
  83. QProcess::execute("xdg-open", QStringList() << dir_path); //works with lxde
  84. #else
  85. QDesktopServices::openUrl(QUrl::fromLocalFile(dir_path));
  86. #endif
  87. }
  88. void DetailsDialog::printInfo()
  89. {
  90. SoundCore *core = SoundCore::instance();
  91. QList <FileInfo *> flist = MetaDataManager::instance()->createPlayList(m_path, true);
  92. QMap <Qmmp::MetaData, QString> metaData;
  93. if(!flist.isEmpty() && QFile::exists(m_item->url()))
  94. metaData = flist.at(0)->metaData();
  95. else
  96. metaData = *m_item;
  97. QString formattedText;
  98. formattedText.append("<TABLE>");
  99. //tags
  100. formattedText += formatRow(tr("Title"), metaData[Qmmp::TITLE]);
  101. formattedText += formatRow(tr("Artist"), metaData[Qmmp::ARTIST]);
  102. formattedText += formatRow(tr("Album"), metaData[Qmmp::ALBUM]);
  103. formattedText += formatRow(tr("Comment"), metaData[Qmmp::COMMENT]);
  104. formattedText += formatRow(tr("Genre"), metaData[Qmmp::GENRE]);
  105. formattedText += formatRow(tr("Composer"), metaData[Qmmp::COMPOSER]);
  106. if(metaData[Qmmp::YEAR] != "0")
  107. formattedText += formatRow(tr("Year"), metaData[Qmmp::YEAR]);
  108. if(metaData[Qmmp::TRACK] != "0")
  109. formattedText += formatRow(tr("Track"), metaData[Qmmp::TRACK]);
  110. if(metaData[Qmmp::DISCNUMBER] != "0")
  111. formattedText += formatRow(tr("Disc number"), metaData[Qmmp::DISCNUMBER]);
  112. //stream information
  113. if(core->state() == Qmmp::Playing && core->url() == metaData.value(Qmmp::URL))
  114. {
  115. if(!core->streamInfo().isEmpty())
  116. {
  117. formattedText.append("<tr>");
  118. formattedText.append("<td colspan=2>");
  119. formattedText.append("<hr>");
  120. formattedText.append("</td>");
  121. formattedText.append("</tr>");
  122. foreach(QString key, core->streamInfo().keys())
  123. formattedText += formatRow(key, core->streamInfo().value(key));
  124. }
  125. }
  126. //audio info
  127. if(!m_metaDataModel)
  128. {
  129. formattedText.append("</TABLE>");
  130. m_ui->textEdit->setHtml(formattedText);
  131. return;
  132. }
  133. QHash <QString, QString> ap = m_metaDataModel->audioProperties();
  134. //line
  135. if(formattedText.trimmed() != "<TABLE>")
  136. {
  137. formattedText.append("<tr>");
  138. formattedText.append("<td colspan=2>");
  139. formattedText.append("<hr>");
  140. formattedText.append("</td>");
  141. formattedText.append("</tr>");
  142. }
  143. foreach(QString key, ap.keys())
  144. formattedText += formatRow(key, ap.value(key));
  145. formattedText.append("</TABLE>");
  146. m_ui->textEdit->setHtml(formattedText);
  147. }
  148. QString DetailsDialog::formatRow(const QString key, const QString value)
  149. {
  150. if(value.isEmpty())
  151. return QString();
  152. QString str("<tr>");
  153. str.append("<td><b>" + key + "</b></td> <td style=\"padding-left: 15px;\">" + value + "</td>");
  154. str.append("</tr>");
  155. return str;
  156. }
  157. void DetailsDialog::on_buttonBox_clicked(QAbstractButton *button)
  158. {
  159. if(m_ui->buttonBox->standardButton(button) == QDialogButtonBox::Save)
  160. {
  161. TagEditor *tab = qobject_cast<TagEditor *> (m_ui->tabWidget->currentWidget());
  162. if(tab)
  163. tab->save();
  164. }
  165. else
  166. reject();
  167. }