Skip to content

Commit

Permalink
Changed default folder to ~/Documents/Recordings and added migration …
Browse files Browse the repository at this point in the history
…wizard
  • Loading branch information
cornedor committed Oct 21, 2015
1 parent dfe317f commit 78e7b4a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
Binary file removed appicons/scalable/apps/icon-launcher.svgz
Binary file not shown.
48 changes: 47 additions & 1 deletion qml/pages/FirstPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Page {
onStopped: musicPlayer.hide();
}

Timer {
id: migrateTimer
interval: 1000;
running: false;
repeat: false;
onTriggered: {
pageStack.push(migrationWizard);
}
}

Drawer {
id: drawer
Expand All @@ -50,6 +59,10 @@ Page {

Component.onCompleted: {
refreshRecordingsList();

if (recorder.shouldMigrate()) {
migrateTimer.start();
}
}

anchors.fill: parent;
Expand Down Expand Up @@ -134,7 +147,7 @@ Page {

Label {
id: filenameLabel
x: Theme.paddingLarge
x: Theme.horizontalPageMargin
text: model.text
anchors.verticalCenter: parent.verticalCenter
color: listItem.highlighted ? Theme.highlightColor : Theme.primaryColor
Expand Down Expand Up @@ -244,4 +257,37 @@ Page {
}
}
}

Component {
id: migrationWizard

Dialog {
Column {
width: parent.width

DialogHeader {
title: "Migration"
}

Label {
text: 'The default folder has changed from "~/Recordings/" ' +
'to "~/Documents/Recordings/". Do you want to move existing ' +
'recordings to the new folder? If you cancel the old directory will be kept.';
font.pixelSize: Theme.fontSizeMedium
wrapMode: Text.WordWrap
width: parent.width - Theme.horizontalPageMargin * 2
x: Theme.horizontalPageMargin
}
}

onAccepted: {
if (!recorder.migrate()) {
banner.notify("Migration failed, old recordings should still be in the old folder.");
} else {
banner.notify("Migration.")
drawer.refreshRecordingsList();
}
}
}
}
}
4 changes: 2 additions & 2 deletions qml/pages/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Page {
text: "Vorbis is a good choice for music. Speex is a good choice for speech. PCM and FLAC are both a lossless format."
wrapMode: Text.WordWrap
font.pixelSize: Theme.fontSizeExtraSmall
width: parent.width - Theme.paddingLarge * 2
x: Theme.paddingLarge
width: parent.width - Theme.horizontalPageMargin * 2
x: Theme.horizontalPageMargin
color: Theme.highlightColor
}
}
Expand Down
3 changes: 1 addition & 2 deletions rpm/harbour-recorder.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ Name: harbour-recorder
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Recorder
Version: 0.2.6
Version: 0.3.0
Release: 1
Group: Qt/Qt
License: GNU GENERAL PUBLIC LICENSE
URL: http://corne.info/
Source0: %{name}-%{version}.tar.bz2
Source100: harbour-recorder.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
BuildRequires: pkgconfig(sailfishapp) >= 0.0.10
BuildRequires: pkgconfig(Qt5Core)
Expand Down
36 changes: 35 additions & 1 deletion src/harbour-recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "harbour-recorder.h"
#include <sailfishapp.h>

const QString Recorder::oldStoragePath = "/Recordings";
const QString Recorder::defaultStoragePath = "/Documents/Recordings";


int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -140,7 +143,7 @@ void Recorder::setLocation(QString location) {

QString Recorder::getLocation() {
QSettings settings;
return settings.value("recorder/fileLocation", QDir::homePath() + "/Recordings").toString();
return settings.value("recorder/fileLocation", QDir::homePath() + Recorder::defaultStoragePath).toString();
}

void Recorder::setCodec(QString codec, int index) {
Expand All @@ -153,3 +156,34 @@ int Recorder::getCodecIndex() {
QSettings settings;
return settings.value("recorder/codecindex", 2).toInt();
}

bool Recorder::shouldMigrate() {
QSettings settings;

if (settings.value("recorder/migrate-1", false).toBool()) {
return false;
}
settings.setValue("recorder/migrate-1", true);

if (!settings.value("recorder/fileLocation").toString().compare(QDir::homePath() + Recorder::oldStoragePath) == 0) {
// The user has set up a custom folder, don't run the migration
return false;
}

// If the old directory exists, migrate the files.
QDir dir(QDir::homePath() + Recorder::oldStoragePath);
return dir.exists();
}

bool Recorder::migrate() {
QSettings settings;
QDir dir;

bool result = dir.rename(QDir::homePath() + Recorder::oldStoragePath, QDir::homePath() + Recorder::defaultStoragePath);

if (result) {
settings.setValue("recorder/fileLocation", QDir::homePath() + Recorder::defaultStoragePath);
}

return result;
}
4 changes: 4 additions & 0 deletions src/harbour-recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Recorder : public QObject {
private:
QAudioRecorder * audioRecorder;
QHash<QString, CodecSetting> codecSettingsMap;
static const QString oldStoragePath;
static const QString defaultStoragePath;
public slots:
void stopRecordingDelayed();
public:
Expand All @@ -29,6 +31,8 @@ public slots:
Q_INVOKABLE QString getLocation();
Q_INVOKABLE int getCodecIndex();
Q_INVOKABLE QStringList getExistingFiles();
Q_INVOKABLE bool shouldMigrate();
Q_INVOKABLE bool migrate();
signals:
void pathCreationFailed();
void recordingChanged();
Expand Down

0 comments on commit 78e7b4a

Please # to comment.