PageRenderTime 91ms CodeModel.GetById 37ms RepoModel.GetById 3ms app.codeStats 0ms

/src/devinfowidget.cpp

https://github.com/salieff/yaudtray
C++ | 163 lines | 89 code | 31 blank | 43 comment | 7 complexity | 7408b7b20c0dd1deec26d2278eb3faf8 MD5 | raw file
  1. /***************************************************************************
  2. * Copyright (C) 2011 by Alexander S. Salieff *
  3. * salieff@mail.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. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include <stdio.h>
  21. #include <QDesktopServices>
  22. #include <QUrl>
  23. #include <QProcess>
  24. #include "devinfowidget.h"
  25. #include "devinfo.h"
  26. #include "helpers.h"
  27. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  28. DevInfoWidget::DevInfoWidget(YaudDeviceInfo *yaudDI, QWidget *parent)
  29. : QWidget(parent)
  30. {
  31. setupUi(this);
  32. convertFrom(yaudDI);
  33. ejectButton->setText("");
  34. connect(ejectButton, SIGNAL(clicked()), this, SLOT(ejectClicked()));
  35. connect(errCloseButton, SIGNAL(clicked()), this, SLOT(errCloseClicked()));
  36. xdgOpen = new QProcess(this);
  37. errIconlabel->setPixmap(yaudIcon("dialog-warning").pixmap(22, 22));
  38. errCloseButton->setIcon(yaudIcon("window-close"));
  39. errCloseButton->setText("");
  40. errGroupBox->hide();
  41. connect(mountPathLabel, SIGNAL(linkActivated(QString)), this, SLOT(mountLinkActivated(QString)));
  42. }
  43. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  44. DevInfoWidget::~DevInfoWidget()
  45. {
  46. }
  47. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  48. void DevInfoWidget::convertFrom(YaudDeviceInfo *yaudDI)
  49. {
  50. QString displayName = yaudDI->displayName;
  51. /*
  52. if (displayName.length() > 16)
  53. {
  54. displayName = yaudDI->displayName.left(7) + QString("...") + yaudDI->displayName.right(7);
  55. nameLabel->setToolTip(yaudDI->displayName);
  56. }
  57. */
  58. nameLabel->setText(displayName + QString(" (") + printSize(yaudDI->size) + QString(")"));
  59. switch(yaudDI->driveType)
  60. {
  61. case YaudDeviceInfo::DRT_CDROM :
  62. diskTypeLabel->setPixmap(yaudIcon("drive-cdrom").pixmap(48, 48));
  63. break;
  64. default :
  65. diskTypeLabel->setPixmap(yaudIcon("drive-removable-media-usb").pixmap(48, 48));
  66. break;
  67. }
  68. OsLabel->setPixmap(iconForFS(yaudDI->fsName).pixmap(22, 22));
  69. if (yaudDI->isMounted)
  70. {
  71. ejectButton->setIcon(yaudIcon("media-eject"));
  72. QString displayPath = yaudDI->mountPath;
  73. /*
  74. if (displayPath.length() > 26)
  75. {
  76. displayPath = yaudDI->mountPath.left(12) + QString("...") + yaudDI->mountPath.right(12);
  77. mountPathLabel->setToolTip(yaudDI->mountPath);
  78. }
  79. */
  80. QString mountUrl = "<A HREF=\"" + yaudDI->mountPath + "\">" + displayPath + "</A>";
  81. mountPathLabel->setText(mountUrl);
  82. }
  83. else
  84. {
  85. ejectButton->setIcon(yaudIcon("system-run"));
  86. mountPathLabel->setText(tr("Not mounted"));
  87. }
  88. if (yaudDI->lastError.isEmpty())
  89. {
  90. errGroupBox->hide();
  91. }
  92. else
  93. {
  94. errNameLabel->setText(yaudDI->lastError);
  95. errTextLabel->setText(yaudDI->lastErrDescription);
  96. errGroupBox->show();
  97. errGroupBox->updateGeometry();
  98. }
  99. udisksPath = yaudDI->udisksPath;
  100. updateGeometry();
  101. }
  102. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  103. QString DevInfoWidget::printSize(qulonglong size)
  104. {
  105. if (size < 1024)
  106. return QString(tr("%1 b")).arg(size);
  107. if (size >= 1024 && size < 1048576)
  108. return QString(tr("%1 Kb")).arg((double)size/1024, 0, 'f', 1);
  109. if (size >= 1048576 && size < 1073741824)
  110. return QString(tr("%1 Mb")).arg((double)size/1048576, 0, 'f', 1);
  111. return QString(tr("%1 Gb")).arg((double)size/1073741824, 0, 'f', 1);
  112. }
  113. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  114. void DevInfoWidget::ejectClicked()
  115. {
  116. emit requestProcessing(udisksPath);
  117. }
  118. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  119. void DevInfoWidget::errCloseClicked()
  120. {
  121. emit requestCloseError(udisksPath);
  122. }
  123. // --------========++++++++ooooooooOOOOOOOOoooooooo++++++++========--------
  124. void DevInfoWidget::mountLinkActivated(QString strLink)
  125. {
  126. // QDesktopServices::openUrl(QUrl(strLink, QUrl::TolerantMode));
  127. // QDesktopServices::openUrl(QUrl::fromLocalFile(strLink));
  128. // QDesktopServices::openUrl(QUrl::fromUserInput(strLink));
  129. QString cmd = QString("xdg-open \"") + strLink + QString("\"");
  130. printf("CMD: %s\n", qPrintable(cmd));
  131. xdgOpen->start(cmd);
  132. }