summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qthelper.cpp22
-rw-r--r--qthelperfromc.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/qthelper.cpp b/qthelper.cpp
index 6e3c957a6..3a4daf833 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -627,6 +627,28 @@ extern "C" const char *system_default_directory(void)
return filename;
}
+extern "C" char *move_away(const char *old_path)
+{
+ if (verbose > 1)
+ qDebug() << "move away" << old_path;
+ QFile oldFile(old_path);
+ QFile newFile;
+ QString newPath;
+ int i = 0;
+ do {
+ newPath = QString(old_path) + QString(".%1").arg(++i);
+ newFile.setFileName(newPath);
+ } while(newFile.exists());
+ if (verbose > 1)
+ qDebug() << "renaming to" << newPath;
+ if (!oldFile.rename(newPath)) {
+ qDebug() << "rename of" << old_path << "to" << newPath << "failed";
+ return strdup("");
+ }
+ return strdup(qPrintable(newPath));
+
+}
+
extern "C" char *get_file_name(const char *fileName)
{
QFileInfo fileInfo(fileName);
diff --git a/qthelperfromc.h b/qthelperfromc.h
index d64bfc04a..21b2a6f80 100644
--- a/qthelperfromc.h
+++ b/qthelperfromc.h
@@ -10,6 +10,7 @@ char *get_file_name(const char *fileName);
void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName);
char *hashstring(char *filename);
bool picture_exists(struct picture *picture);
+char *move_away(const char *path);
const char *local_file_path(struct picture *picture);
void savePictureLocal(struct picture *picture, const char *data, int len);
void cache_picture(struct picture *picture);