Commit 077d9a4f authored by camilo higuita's avatar camilo higuita

added desktop file and initial work on allowing opening external files close #24 close #25

parent 3546ec79
......@@ -3,12 +3,45 @@
#include <QQmlContext>
#include <QQuickStyle>
#include <QIcon>
#include <QCommandLineParser>
#include <QFileInfo>
#include "src/pix.h"
#ifdef Q_OS_ANDROID
#include "./3rdparty/kirigami/src/kirigamiplugin.h"
#endif
QStringList getFolderImages(const QString &path)
{
QStringList urls;
if (QFileInfo(path).isDir())
{
QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) urls<<it.next();
} else if (QFileInfo(path).isFile()) urls<<path;
return urls;
}
QStringList openFiles(const QStringList &files)
{
QStringList urls;
if(files.size()>1)
urls = files;
else
{
auto folder = QFileInfo(files.first()).dir().absolutePath();
urls = getFolderImages(folder);
urls.removeOne(QString(files.first()));
urls.insert(0, QString(files.first()));
}
return urls;
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
......@@ -19,11 +52,25 @@ int main(int argc, char *argv[])
app.setApplicationDisplayName(PIX::App);
app.setWindowIcon(QIcon(":/img/assets/pix.png"));
QCommandLineParser parser;
parser.setApplicationDescription("Pix Image gallery viewer");
const QCommandLineOption versionOption = parser.addVersionOption();
parser.addOption(versionOption);
parser.process(app);
const QStringList args = parser.positionalArguments();
QStringList pics;
if(!args.isEmpty())
pics = openFiles(args);
#ifdef Q_OS_ANDROID
KirigamiPlugin::getInstance().registerTypes();
//#else
// if(QQuickStyle::availableStyles().contains("nomad"))
// QQuickStyle::setStyle("nomad");
//#else
// if(QQuickStyle::availableStyles().contains("nomad"))
// QQuickStyle::setStyle("nomad");
#endif
Pix pix;
......@@ -33,6 +80,8 @@ int main(int argc, char *argv[])
{
qDebug()<<"FINISHED LOADING QML APP";
pix.refreshCollection();
if(!pics.isEmpty())
pix.openPics(pics);
});
auto context = engine.rootContext();
......
[Desktop Entry]
Name=Pix
Comment=Image gallery viewer
TryExec=pix
Exec=pix %U
Terminal=false
Type=Application
Categories=Qt;Graphics;Viewer;KDE;
StartupNotify=true
Icon=pix
MimeType=image/gif;image/jpeg;image/png;image/bmp;image/x-eps;image/x-ico;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xbitmap;image/x-xpixmap;image/tiff;image/x-psd;image/x-webp;image/webp;
# Generic name with translations
GenericName=Image Gallery
pix.png

1.07 KB

......@@ -73,7 +73,7 @@ class FileLoader : public DBActions
auto sourceUrl = info.dir().path();
PIX::DB trackMap =
PIX::DB picMap =
{
{PIX::KEY::URL, url},
{PIX::KEY::TITLE, title},
......@@ -85,7 +85,7 @@ class FileLoader : public DBActions
{PIX::KEY::FORMAT, format}
};
this->addPic(trackMap);
this->addPic(picMap);
newPics++;
}
}else break;
......
......@@ -15,6 +15,7 @@ import "view_models"
import "widgets/dialogs/share"
import "widgets/views/Pix.js" as PIX
import "widgets/views/Viewer/Viewer.js" as VIEWER
Kirigami.ApplicationWindow
{
......@@ -150,6 +151,7 @@ Kirigami.ApplicationWindow
target: pix
onRefreshViews: PIX.refreshViews()
onViewPics: VIEWER.open(pics, 0)
}
}
......@@ -48,6 +48,35 @@ Pix::~Pix()
delete this->fileLoader;
}
void Pix::openPics(const QStringList &pics)
{
QVariantList data;
for(auto url : pics)
{
QFileInfo info(url);
auto title = info.baseName();
auto format = info.suffix();
auto sourceUrl = info.dir().path();
QVariantMap picMap =
{
{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::TITLE], title},
{PIX::KEYMAP[PIX::KEY::FAV], "0"},
{PIX::KEYMAP[PIX::KEY::RATE], "0"},
{PIX::KEYMAP[PIX::KEY::COLOR], ""},
{PIX::KEYMAP[PIX::KEY::SOURCES_URL], sourceUrl},
{PIX::KEYMAP[PIX::KEY::PIC_DATE], info.created().toString()},
{PIX::KEYMAP[PIX::KEY::FORMAT], format}
};
data << picMap;
}
emit viewPics(data);
}
void Pix::refreshCollection()
{
this->populateDB({PIX::PicturesPath, PIX::DownloadsPath, PIX::DocumentsPath});
......
......@@ -20,37 +20,40 @@ class FileLoader;
class Pix : public DBActions
{
Q_OBJECT
Q_OBJECT
public:
explicit Pix(QObject* parent = nullptr);
~Pix();
public:
explicit Pix(QObject* parent = nullptr);
~Pix();
Q_INVOKABLE void refreshCollection();
Q_INVOKABLE void openPics(const QStringList &pics);
Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE bool run(const QString &query);
Q_INVOKABLE void refreshCollection();
Q_INVOKABLE static QString pixColor();
Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE bool run(const QString &query);
Q_INVOKABLE static int screenGeometry(QString &side);
Q_INVOKABLE static int cursorPos(QString &axis);
Q_INVOKABLE static QString pixColor();
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static int screenGeometry(QString &side);
Q_INVOKABLE static int cursorPos(QString &axis);
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
private:
FileLoader *fileLoader;
Q_INVOKABLE static QVariantList openWith(const QString &url);
Q_INVOKABLE static void runApplication(const QString &exec, const QString &url);
void populateDB(const QStringList &paths);
private:
FileLoader *fileLoader;
signals:
void refreshViews(QVariantMap tables);
void populateDB(const QStringList &paths);
signals:
void refreshViews(QVariantMap tables);
void viewPics(QVariantList pics);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment