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"
26 #include "constants.h"
27 #include "compatibility/pathsservice.h"
28 #include <QDesktopServices>
30 SnapshotSettings::SnapshotSettings(QWidget *parent) : QWidget(parent) {
31 QBoxLayout *layout = new QHBoxLayout(this);
32 layout->setContentsMargins(5, 0, 10, 0);
33 layout->setSpacing(5);
35 thumb = new QToolButton();
36 thumb->setStyleSheet("border:0");
37 thumb->setCursor(Qt::PointingHandCursor);
38 connect(thumb, SIGNAL(clicked()), SLOT(openFile()));
39 layout->addWidget(thumb);
41 message = new QLabel();
42 connect(message, SIGNAL(linkActivated(QString)), this, SLOT(showFile()));
43 layout->addWidget(message);
45 changeFolderButton = new QPushButton();
46 changeFolderButton->setAttribute(Qt::WA_MacMiniSize);
47 changeFolderButton->setText(tr("Change location..."));
48 connect(changeFolderButton, SIGNAL(clicked()), SLOT(changeFolder()));
49 layout->addWidget(changeFolderButton);
52 void SnapshotSettings::setSnapshot(const QPixmap &pixmap, const QString &filename) {
53 QPixmap p = pixmap.scaledToHeight(message->sizeHint().height());
56 thumb->setIconSize(p.size());
57 // thumb->setPixmap(pixmap.scaledToHeight(message->sizeHint().height()));
59 this->filename = filename;
60 QFileInfo fileInfo(filename);
61 QString path = fileInfo.absolutePath();
62 QString display = displayPath(path);
64 QString msg = tr("Snapshot saved to %1")
65 .arg("<a href='showFile' style='text-decoration:none; color:palette(text); font-weight:bold'>%1</a>")
67 message->setText(msg);
70 void SnapshotSettings::setCurrentLocation(const QString &location) {
72 settings.setValue("snapshotsFolder", location);
75 QString SnapshotSettings::getCurrentLocation() {
77 QString location = settings.value("snapshotsFolder").toString();
78 if (location.isEmpty() || !QFile::exists(location)) {
79 location = Paths::getPicturesLocation();
81 location += "/MinitubeforYouTube";
87 QString SnapshotSettings::displayPath(const QString &path) {
89 return QDir(path).dirName();
92 const QString home = Paths::getHomeLocation();
93 QString displayPath = path;
94 displayPath = displayPath.remove(home + "/");
98 void SnapshotSettings::changeFolder() {
99 const QString path = Paths::getHomeLocation();
101 QFileDialog* dialog = new QFileDialog(this);
102 dialog->setFileMode(QFileDialog::Directory);
103 dialog->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
104 dialog->setDirectory(path);
105 dialog->open(this, SLOT(folderChosen(const QString &)));
107 QString folder = QFileDialog::getExistingDirectory(window(), QString(),
109 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly);
110 folderChosen(folder);
114 void SnapshotSettings::folderChosen(const QString &dir) {
115 if (!dir.isEmpty()) {
116 setCurrentLocation(dir);
117 QString status = tr("Snapshots location changed.");
118 MainWindow::instance()->showMessage(status);
122 void SnapshotSettings::showFile() {
123 QFileInfo info(filename);
125 mac::showInFinder(info.absoluteFilePath());
127 QUrl url = QUrl::fromLocalFile(info.absolutePath());
128 QDesktopServices::openUrl(url);
132 void SnapshotSettings::openFile() {
133 QDesktopServices::openUrl(QUrl::fromLocalFile(filename));