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>
27 #include "constants.h"
29 SnapshotSettings::SnapshotSettings(QWidget *parent) : QWidget(parent) {
30 QBoxLayout *layout = new QHBoxLayout(this);
31 layout->setContentsMargins(5, 0, 10, 0);
32 layout->setSpacing(5);
34 thumb = new QToolButton();
35 thumb->setStyleSheet("border:0");
36 thumb->setCursor(Qt::PointingHandCursor);
37 connect(thumb, SIGNAL(clicked()), SLOT(openFile()));
38 layout->addWidget(thumb);
40 message = new QLabel();
41 connect(message, SIGNAL(linkActivated(QString)), this, SLOT(showFile()));
42 layout->addWidget(message);
44 changeFolderButton = new QPushButton();
45 changeFolderButton->setAttribute(Qt::WA_MacMiniSize);
46 changeFolderButton->setText(tr("Change location..."));
47 connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
48 layout->addWidget(changeFolderButton);
51 void SnapshotSettings::setSnapshot(const QPixmap &pixmap, const QString &filename) {
52 QPixmap p = pixmap.scaledToHeight(message->sizeHint().height());
55 thumb->setIconSize(p.size());
56 // thumb->setPixmap(pixmap.scaledToHeight(message->sizeHint().height()));
58 this->filename = filename;
59 QFileInfo fileInfo(filename);
60 QString path = fileInfo.absolutePath();
61 QString display = displayPath(path);
63 QString msg = tr("Snapshot saved to %1")
64 .arg("<a href='showFile' style='text-decoration:none; color:palette(text); font-weight:bold'>%1</a>")
66 message->setText(msg);
69 void SnapshotSettings::setCurrentLocation(const QString &location) {
71 settings.setValue("snapshotsFolder", location);
74 QString SnapshotSettings::getCurrentLocation() {
76 QString location = settings.value("snapshotsFolder").toString();
77 if (location.isEmpty() || !QFile::exists(location)) {
78 #if QT_VERSION >= 0x050000
79 location = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
81 location = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
84 location += "/MinitubeforYouTube";
90 QString SnapshotSettings::displayPath(const QString &path) {
92 return QDir(path).dirName();
95 #if QT_VERSION >= 0x050000
96 QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
98 QString home = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
100 QString displayPath = path;
101 displayPath = displayPath.remove(home + "/");
105 void SnapshotSettings::changeFolder() {
108 QFileDialog* dialog = new QFileDialog(this);
109 dialog->setFileMode(QFileDialog::Directory);
110 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
111 #if QT_VERSION >= 0x050000
112 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
114 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
116 dialog->setDirectory(path);
117 dialog->open(this, SLOT(folderChosen(const QString &)));
120 #if QT_VERSION >= 0x050000
121 path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
123 path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
125 QString folder = QFileDialog::getExistingDirectory(window(), QString(),
127 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
128 folderChosen(folder);
132 void SnapshotSettings::folderChosen(const QString &dir) {
133 if (!dir.isEmpty()) {
134 setCurrentLocation(dir);
135 QString status = tr("Snapshots location changed.");
136 MainWindow::instance()->showMessage(status);
140 void SnapshotSettings::showFile() {
141 QFileInfo info(filename);
143 mac::showInFinder(info.absoluteFilePath());
145 QUrl url = QUrl::fromLocalFile(info.absolutePath());
146 QDesktopServices::openUrl(url);
150 void SnapshotSettings::openFile() {
151 QDesktopServices::openUrl(QUrl::fromLocalFile(filename));