3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #include "snapshotsettings.h"
22 #include "mainwindow.h"
23 #include <QDesktopServices>
28 SnapshotSettings::SnapshotSettings(QWidget *parent) : QWidget(parent) {
29 QBoxLayout *layout = new QHBoxLayout(this);
30 layout->setContentsMargins(5, 0, 10, 0);
31 layout->setSpacing(5);
33 thumb = new QToolButton();
34 thumb->setStyleSheet("border:0");
35 thumb->setCursor(Qt::PointingHandCursor);
36 connect(thumb, SIGNAL(clicked()), SLOT(openFile()));
37 layout->addWidget(thumb);
39 message = new QLabel();
40 connect(message, SIGNAL(linkActivated(QString)), this, SLOT(showFile()));
41 layout->addWidget(message);
43 changeFolderButton = new QPushButton();
44 changeFolderButton->setAttribute(Qt::WA_MacMiniSize);
45 changeFolderButton->setText(tr("Change location..."));
46 connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
47 layout->addWidget(changeFolderButton);
50 void SnapshotSettings::setSnapshot(const QPixmap &pixmap, const QString &filename) {
51 QPixmap p = pixmap.scaledToHeight(message->sizeHint().height());
54 thumb->setIconSize(p.size());
55 // thumb->setPixmap(pixmap.scaledToHeight(message->sizeHint().height()));
57 this->filename = filename;
58 QFileInfo fileInfo(filename);
59 QString path = fileInfo.absolutePath();
60 QString display = displayPath(path);
62 QString msg = tr("Snapshot saved to %1")
63 .arg("<a href='showFile' style='text-decoration:none; color:palette(text); font-weight:bold'>%1</a>")
65 message->setText(msg);
68 void SnapshotSettings::setCurrentLocation(const QString &location) {
70 settings.setValue("snapshotsFolder", location);
73 QString SnapshotSettings::getCurrentLocation() {
75 QString location = settings.value("snapshotsFolder").toString();
76 if (location.isEmpty() || !QFile::exists(location)) {
77 #if QT_VERSION >= 0x050000
78 location = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
80 location = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
86 QString SnapshotSettings::displayPath(const QString &path) {
88 return QDir(path).dirName();
91 #if QT_VERSION >= 0x050000
92 QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
94 QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
96 QString displayPath = path;
97 displayPath = displayPath.remove(home + "/");
101 void SnapshotSettings::changeFolder() {
104 QFileDialog* dialog = new QFileDialog(this);
105 dialog->setFileMode(QFileDialog::Directory);
106 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
107 #if QT_VERSION >= 0x050000
108 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
110 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
112 dialog->setDirectory(path);
113 dialog->open(this, SLOT(folderChosen(const QString &)));
116 #if QT_VERSION >= 0x050000
117 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
119 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
121 QString folder = QFileDialog::getExistingDirectory(window(), QString(),
123 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
124 folderChosen(folder);
128 void SnapshotSettings::folderChosen(const QString &dir) {
129 if (!dir.isEmpty()) {
130 setCurrentLocation(dir);
131 QString status = tr("Snapshots location changed.");
132 MainWindow::instance()->showMessage(status);
136 void SnapshotSettings::showFile() {
137 QFileInfo info(filename);
139 mac::showInFinder(info.absoluteFilePath());
141 QUrl url = QUrl::fromLocalFile(info.absolutePath());
142 QDesktopServices::openUrl(url);
146 void SnapshotSettings::openFile() {
147 QDesktopServices::openUrl(QUrl::fromLocalFile(filename));