summaryrefslogtreecommitdiffstats
path: root/depends
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-18 20:52:17 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-18 20:52:17 +0200
commitc92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d (patch)
tree7be301a5123e216a41646f9639ec887609497a87 /depends
parent253067c782955380bbf66ac0475dc954375b1ff4 (diff)
downloadMultiMC-c92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d.tar
MultiMC-c92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d.tar.gz
MultiMC-c92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d.tar.lz
MultiMC-c92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d.tar.xz
MultiMC-c92ad7dcf86f2e5e71d71a68e24e79fbdeceb56d.zip
Drag and Drop, mod management.
Diffstat (limited to 'depends')
-rw-r--r--depends/util/include/pathutils.h5
-rw-r--r--depends/util/src/pathutils.cpp28
2 files changed, 29 insertions, 4 deletions
diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h
index d4f41da3..40bb9e74 100644
--- a/depends/util/include/pathutils.h
+++ b/depends/util/include/pathutils.h
@@ -33,5 +33,10 @@ LIBUTIL_EXPORT bool ensurePathExists(QString filenamepath);
LIBUTIL_EXPORT bool copyPath(QString src, QString dst);
+/// Opens the given file in the default application.
+LIBUTIL_EXPORT void openFileInDefaultProgram ( QString filename );
+
+/// Opens the given directory in the default application.
+LIBUTIL_EXPORT void openDirInDefaultProgram ( QString dirpath, bool ensureExists = false );
#endif // PATHUTILS_H
diff --git a/depends/util/src/pathutils.cpp b/depends/util/src/pathutils.cpp
index 97287840..5bafdf0f 100644
--- a/depends/util/src/pathutils.cpp
+++ b/depends/util/src/pathutils.cpp
@@ -17,6 +17,8 @@
#include <QFileInfo>
#include <QDir>
+#include <QDesktopServices>
+#include <QUrl>
QString PathCombine(QString path1, QString path2)
{
@@ -70,7 +72,7 @@ bool ensurePathExists(QString filenamepath)
{
QFileInfo a ( filenamepath );
QDir dir;
- return (dir.mkpath ( a.path() ));
+ return (dir.mkpath ( a.filePath() ));
}
bool copyPath(QString src, QString dst)
@@ -78,12 +80,14 @@ bool copyPath(QString src, QString dst)
QDir dir(src);
if (!dir.exists())
return false;
+ if(!ensurePathExists(dst))
+ return false;
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
- QString dst_path = dst + QDir::separator() + d;
- dir.mkpath(dst_path);
- copyPath(src+ QDir::separator() + d, dst_path);
+ QString inner_src = src+ QDir::separator() + d;
+ QString inner_dst = dst + QDir::separator() + d;
+ copyPath(inner_src, inner_dst);
}
foreach (QString f, dir.entryList(QDir::Files))
@@ -92,3 +96,19 @@ bool copyPath(QString src, QString dst)
}
return true;
}
+
+void openDirInDefaultProgram ( QString path, bool ensureExists )
+{
+ QDir parentPath;
+ QDir dir( path );
+ if(!dir.exists())
+ {
+ parentPath.mkpath(dir.absolutePath());
+ }
+ QDesktopServices::openUrl ( "file:///" + dir.absolutePath() );
+}
+
+void openFileInDefaultProgram ( QString filename )
+{
+ QDesktopServices::openUrl ( "file:///" + QFileInfo ( filename ).absolutePath() );
+}