Skip to content

Commit

Permalink
open sessions from manage session dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dheerajshenoy committed Aug 9, 2024
1 parent 5c114c3 commit a86ab92
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ Only for **Linux**.

![image](https://github.com/user-attachments/assets/c5f42acb-0760-45e7-a41d-11fac2570c41)



<a name="introduction" />

# Introduction
Expand Down Expand Up @@ -176,6 +174,10 @@ Note that if the `keybindings` table is present in the `Defaults` table, then de

# Changelogs and Bug Fixes

- 09 Aug 2024

- Open sessions from Manage Session Dialog

- 08 Aug 2024

- Remove & Rename session files
Expand All @@ -192,7 +194,6 @@ Note that if the `keybindings` table is present in the `Defaults` table, then de

![image](https://github.com/user-attachments/assets/1c8f2e7d-7efd-420e-8ec0-dd3cf78a3409)


- 07 Aug 2024

- EXIF Metadata support (JPEG metadata)
Expand Down
1 change: 1 addition & 0 deletions src/ImageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ImageWidget::ImageWidget(QWidget *parent)
m_scene = new QGraphicsScene(this);
setScene(m_scene);


m_pixmapItem = new QGraphicsPixmapItem;
m_movieItem = new MovieItem;
m_scene->addItem(m_pixmapItem);
Expand Down
24 changes: 19 additions & 5 deletions src/ManageSessionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
ManageSessionsDialog::ManageSessionsDialog(QString &sessionDirPath, QWidget *parent)
: QDialog(parent), session_path(sessionDirPath)
{
table->setColumnCount(2);
table->setHorizontalHeaderLabels({ "Session Name", "Images" });
table->setColumnCount(3);
table->setHorizontalHeaderLabels({ "Session Name", "Date Modified", "Images" });

auto files = QDir(sessionDirPath).entryList(QStringList() << "*.imgv" << "*.IMGV", QDir::Files);
table->setRowCount(files.size());
Expand All @@ -17,10 +17,14 @@ ManageSessionsDialog::ManageSessionsDialog(QString &sessionDirPath, QWidget *par
for(int i=0; i < files.size(); i++)
{
QTableWidgetItem *session_file = new QTableWidgetItem(QFileInfo(files[i]).baseName());
QStringList imgfiles = utils::getImagesFromSessionFile(QString("%1%2%3").arg(sessionDirPath).arg(QDir::separator()).arg(files[i]));
Custom date_and_files = utils::getDateandImagesFromSessionFile(QString("%1%2%3").arg(sessionDirPath).arg(QDir::separator()).arg(files[i]));
auto imgfiles = date_and_files.files;
QTableWidgetItem *img_count = new QTableWidgetItem(QString::number(imgfiles.size()));
QTableWidgetItem *date = new QTableWidgetItem(date_and_files.date);
img_count->setToolTip(imgfiles.join("\n"));
table->setItem(i, 0, session_file);
table->setItem(i, 1, img_count);
table->setItem(i, 1, date);
table->setItem(i, 2, img_count);
}

layout->addWidget(table);
Expand All @@ -33,15 +37,25 @@ ManageSessionsDialog::ManageSessionsDialog(QString &sessionDirPath, QWidget *par
contextMenu->addAction(renameSession);
contextMenu->addAction(deleteSession);
contextMenu->addAction(openInExplorer);
contextMenu->addAction(_openSession);

table->setContextMenuPolicy(Qt::CustomContextMenu);

connect(renameSession, &QAction::triggered, this, &ManageSessionsDialog::RenameSession);
connect(deleteSession, &QAction::triggered, this, &ManageSessionsDialog::DeleteSession);
connect(openInExplorer, &QAction::triggered, this, &ManageSessionsDialog::OpenInExplorer);
connect(_openSession, &QAction::triggered, this, &ManageSessionsDialog::OpenSession);
connect(table, &QTableWidget::customContextMenuRequested, this, &ManageSessionsDialog::showContextMenu);
}

void ManageSessionsDialog::OpenSession() noexcept
{
auto sessions = table->selectedItems();

for(int i=0; i < sessions.count() / 2; i += 2)
emit openSession(session_path + QDir::separator() + sessions[i]->text() + ".imgv");
}

void ManageSessionsDialog::showContextMenu(const QPointF loc) noexcept
{
contextMenu->exec(mapToGlobal(loc.toPoint()));
Expand All @@ -59,7 +73,7 @@ void ManageSessionsDialog::DeleteSession() noexcept
msgbox.setStandardButtons(QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No);
msgbox.setWindowTitle("Deleting Session");
bool check = true;
for(int i=0; i < sessions.count(); i += 2)
for(int i=0; i < sessions.count() / 2; i += 2)
{
auto session = sessions[i];
auto filepath = QString("%1%2%3").arg(session_path).arg(QDir::separator()).arg(session->text() + ".imgv");
Expand Down
7 changes: 6 additions & 1 deletion src/ManageSessionsDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@

class ManageSessionsDialog : public QDialog
{
Q_OBJECT
public:
ManageSessionsDialog(QString &sessionDirPath, QWidget *parent = nullptr);
~ManageSessionsDialog() {}

signals:
void openSession(QString);

private:
QVBoxLayout *layout = new QVBoxLayout();
QTableWidget *table = new QTableWidget();
QMenu *contextMenu = new QMenu();
QAction *renameSession = new QAction("Rename Session");
QAction *deleteSession = new QAction("Delete Session");
QAction *openInExplorer = new QAction("Open in Explorer");
QAction *_openSession = new QAction("Open Session");
QPushButton *done_btn = new QPushButton("Done");

void OpenSession() noexcept;
void RenameSession() noexcept;
void OpenInExplorer() noexcept;
void DeleteSession() noexcept;
void showContextMenu(const QPointF loc) noexcept;
QStringList getSessions() noexcept;


QString session_path;
};

Expand Down
1 change: 1 addition & 0 deletions src/StatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ StatusBar::StatusBar(QWidget *parent)
noteModifiedLabel->setToolTip("Note has unsaved changes. Switching to other image will delete the unsaved changes");
sessionLabel->setToolTip("Current session");

layout->setContentsMargins(2, 2, 2, 2);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);


Expand Down
5 changes: 4 additions & 1 deletion src/imgv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ IMGV::IMGV(argparse::ArgumentParser &parser, QWidget *parent)
splitter->addWidget(m_thumbnail_view);
m_right_pane->setLayout(m_right_pane_layout);

m_right_pane_layout->setContentsMargins(0, 0, 0, 0);

m_right_pane_splitter->addWidget(m_img_widget);
m_right_pane_splitter->addWidget(m_note_holder);

Expand All @@ -53,7 +55,7 @@ IMGV::IMGV(argparse::ArgumentParser &parser, QWidget *parent)
layout->addWidget(m_statusbar);
setCentralWidget(centralWidget);

layout->setContentsMargins(0, 0, 0, 0);
layout->setContentsMargins(5, 5, 5, 5);
centralWidget->setContentsMargins(0, 0, 0, 0);
this->setContentsMargins(0, 0, 0, 0);

Expand Down Expand Up @@ -284,6 +286,7 @@ void IMGV::initMenu()

connect(tools__manage_sessions, &QAction::triggered, this, [&]() {
ManageSessionsDialog *md = new ManageSessionsDialog(m_sessions_dir_path, this);
connect(md, &ManageSessionsDialog::openSession, this, [&](QString name) { openSession(name); });
md->open();
});

Expand Down
45 changes: 45 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,48 @@ QStringList utils::getImagesFromSessionFile(const QString &sessionfilepath) noex
ifs.close();
return imgfiles;
}

Custom utils::getDateandImagesFromSessionFile(const QString &sessionfilepath) noexcept
{
using namespace rapidjson;
std::ifstream ifs(sessionfilepath.toStdString());

if (!ifs.is_open()) {
return {};
}

IStreamWrapper isw(ifs);

Document doc;
doc.ParseStream(isw);

if (doc.HasParseError())
{
return {};
}

QStringList imgfiles;
if (doc.HasMember("files") && doc["files"].IsArray())
{
const Value& files_arr = doc["files"];
for(SizeType i=0; i < files_arr.Size(); i++)
{
if (files_arr[i].IsObject())
{
auto file = files_arr[i].GetObject();
if (file.HasMember("path") && file["path"].IsString() && file.HasMember("note") && file["note"].IsString())
{
imgfiles << file["path"].GetString();
}
}
}
}

QString date;
if (doc.HasMember("date") && doc["date"].IsString())
date = doc["date"].GetString();
else
date = "N/A";
ifs.close();
return Custom{ imgfiles, date };
}
8 changes: 8 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <qt6/QtCore/QString>
#include <qt6/QtCore/QFile>
#include <qt6/QtCore/QFileInfo>
#include <qt6/QtCore/QStringList>
#include <qt6/QtGui/QPixmap>
#include <qt6/QtCore/QMimeData>
#include <qt6/QtCore/QMimeDatabase>
Expand All @@ -21,6 +22,12 @@ struct Dimension
int height;
};

struct Custom
{
QStringList files;
QString date;
};

class utils
{

Expand All @@ -33,6 +40,7 @@ class utils
static QImage decodeWebPToImage(const QString &filePath) noexcept;
static QString imageFormatToString(const QImage::Format format) noexcept;
static QStringList getImagesFromSessionFile(const QString &session_file) noexcept;
static Custom getDateandImagesFromSessionFile(const QString &session_file) noexcept;
};

#endif

0 comments on commit a86ab92

Please sign in to comment.