From 1618413050056ee1e49bb32b448303c6a87eb936 Mon Sep 17 00:00:00 2001 From: Nighty3098 Date: Sun, 5 May 2024 16:44:51 +0700 Subject: [PATCH 1/5] Edited --- src/CodeKeeper/keeperFunc/functional.cpp | 8 + src/CodeKeeper/keeperFunc/notesFunc.cpp | 482 ++++++++++++----------- src/CodeKeeper/mainwindow.cpp | 9 +- src/CodeKeeper/mainwindow.h | 8 + 4 files changed, 274 insertions(+), 233 deletions(-) diff --git a/src/CodeKeeper/keeperFunc/functional.cpp b/src/CodeKeeper/keeperFunc/functional.cpp index f8ffa7bb..4bc2e71c 100644 --- a/src/CodeKeeper/keeperFunc/functional.cpp +++ b/src/CodeKeeper/keeperFunc/functional.cpp @@ -48,6 +48,14 @@ void MainWindow::getSettingsData() isVisibleFolders = globalSettings->value("isVisibleFolders", true).toBool(); isVisiblePreview = globalSettings->value("isVisiblePreview", false).toBool(); isViewMode = globalSettings->value("isViewMode", false).toBool(); + git_repo = globalSettings->value("git_repo").value(); + git_user = globalSettings->value("git_user").value(); + git_token = globalSettings->value("git_token").value(); + isAutoSyncB = globalSettings->value("isAutoSync").value(); + + qDebug() << dir << selectedFont << font_size << theme << isCustomTitlebar << sortNotesRole + << isAutoSyncing << isVisibleNotesList << isVisibleFolders << isVisiblePreview + << isViewMode << git_repo << git_user << git_token << isAutoSyncB; } void MainWindow::setConnectionStatus() diff --git a/src/CodeKeeper/keeperFunc/notesFunc.cpp b/src/CodeKeeper/keeperFunc/notesFunc.cpp index 4a398ec1..6594b646 100644 --- a/src/CodeKeeper/keeperFunc/notesFunc.cpp +++ b/src/CodeKeeper/keeperFunc/notesFunc.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include +#include QModelIndex indexFromItem(QTreeWidgetItem *item, int column) { } @@ -20,6 +22,26 @@ bool createFile(const QString &path) } } +void MainWindow::exportNoteToPdf() +{ + QModelIndex selectedIndex = notesList->currentIndex(); + QFileSystemModel *fileSystemModel = static_cast(notesList->model()); + QString filePath = fileSystemModel->filePath(selectedIndex); + qDebug() << "File Path: " << filePath; + + QFile markdownFile(filePath); +} + +void MainWindow::exportNoteToHtml() +{ + QModelIndex selectedIndex = notesList->currentIndex(); + QFileSystemModel *fileSystemModel = static_cast(notesList->model()); + QString filePath = fileSystemModel->filePath(selectedIndex); + qDebug() << "File Path: " << filePath; + + QFile markdownFile(filePath); +} + void MainWindow::loadNotes() { dir = globalSettings->value("path").value(); @@ -54,236 +76,6 @@ void MainWindow::setSortByName() notesList->sortByColumn(0, Qt::SortOrder()); } -void MainWindow::updateMDPreview() -{ - QString md = noteEdit->toPlainText(); - - QString html; - md_html( - md.toUtf8().constData(), md.length(), - [](const MD_CHAR *html, MD_SIZE html_size, void *userdata) { - QString *htmlPtr = static_cast(userdata); - QString htmlStr(QString::fromUtf8(reinterpret_cast(html), html_size)); - *htmlPtr += htmlStr; - }, - &html, 0, 0); - html += ""; - - QString html_result = - "" - "" - "" - "" - + html; - - mdPreview->setHtml(html_result); -} - void MainWindow::saveNote() { QModelIndex index = notesList->currentIndex(); @@ -618,3 +410,233 @@ void MainWindow::setTable() noteEdit->setTextCursor(cursor); } + +void MainWindow::updateMDPreview() +{ + QString md = noteEdit->toPlainText(); + + QString html; + md_html( + md.toUtf8().constData(), md.length(), + [](const MD_CHAR *html, MD_SIZE html_size, void *userdata) { + QString *htmlPtr = static_cast(userdata); + QString htmlStr(QString::fromUtf8(reinterpret_cast(html), html_size)); + *htmlPtr += htmlStr; + }, + &html, 0, 0); + html += ""; + + QString html_result = + "" + "" + "" + "" + + html; + + mdPreview->setHtml(html_result); +} diff --git a/src/CodeKeeper/mainwindow.cpp b/src/CodeKeeper/mainwindow.cpp index 59e7d591..f5033f23 100644 --- a/src/CodeKeeper/mainwindow.cpp +++ b/src/CodeKeeper/mainwindow.cpp @@ -108,7 +108,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) menuLayout->setAlignment(Qt::AlignHCenter); QStringList filters; - filters << "" << "*.md" << "*.html" << "*.txt"; + filters << "" + << "*.md" + << "*.html" + << "*.txt"; iconProvider = new CustomIconProvider(); @@ -225,8 +228,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) QMenu *exportMenu = new QMenu("Export as", menu); exportMenu->setIcon(QIcon(":/export.png")); - exportToHtml = exportMenu->addAction("HTML"); - exportToPdf = exportMenu->addAction("Pdf"); + exportToHtml = exportMenu->addAction("HTML", this, SLOT(exportNoteToHtml())); + exportToPdf = exportMenu->addAction("Pdf", this, SLOT(exportNoteToPdf())); menu->addMenu(editMenu); menu->addMenu(viewMenu); diff --git a/src/CodeKeeper/mainwindow.h b/src/CodeKeeper/mainwindow.h index 9fa31684..b39c743b 100644 --- a/src/CodeKeeper/mainwindow.h +++ b/src/CodeKeeper/mainwindow.h @@ -100,6 +100,11 @@ class MainWindow : public QMainWindow int sortNotesRole; bool isAutoSyncing; + QString git_repo; + QString git_user; + QString git_token; + bool isAutoSyncB; + QFileSystemModel *notesDirModel; QFileSystemModel *noteFileModel; @@ -183,6 +188,9 @@ private slots: void create_tasks_connection(); void create_projects_connection(); + void exportNoteToPdf(); + void exportNoteToHtml(); + void updateTaskStatus(QString *task, QString *status, QString *cT); void updateTaskData(QString *task, QString *status, QString *cT); void onMovingTaskFrom(QListWidgetItem *item, QListWidget *list); From 265470d664e3c722a9dcb051ba4e31f0c1fd3f08 Mon Sep 17 00:00:00 2001 From: Nighty3098 Date: Sun, 5 May 2024 17:32:29 +0700 Subject: [PATCH 2/5] Edited --- rm_cache.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rm_cache.sh b/rm_cache.sh index 4fca4941..97bd58fb 100755 --- a/rm_cache.sh +++ b/rm_cache.sh @@ -1,5 +1,6 @@ #!/bin/bash +rm -rf src/CodeKeeper/build rm src/CodeKeeper/CodeKeeper.pro.user rm src/CodeKeeper/CodeKeeper.pro.user.1f90c22 rm src/CodeKeeper/main.o @@ -35,4 +36,4 @@ rm src/CodeKeeper/settingswindow.o rm src/CodeKeeper/syncwindow.o rm src/CodeKeeper/ui_qplaintexteditsearchwidget.h -echo "Done!" \ No newline at end of file +echo "Done!" From c50078d214dac62f5e083132c0488fab8abaa51b Mon Sep 17 00:00:00 2001 From: Nighty3098 Date: Sun, 5 May 2024 17:32:58 +0700 Subject: [PATCH 3/5] Added export to HTML --- src/CodeKeeper/keeperFunc/notesFunc.cpp | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/CodeKeeper/keeperFunc/notesFunc.cpp b/src/CodeKeeper/keeperFunc/notesFunc.cpp index 6594b646..5e6589c9 100644 --- a/src/CodeKeeper/keeperFunc/notesFunc.cpp +++ b/src/CodeKeeper/keeperFunc/notesFunc.cpp @@ -39,7 +39,31 @@ void MainWindow::exportNoteToHtml() QString filePath = fileSystemModel->filePath(selectedIndex); qDebug() << "File Path: " << filePath; - QFile markdownFile(filePath); + QString str = QFileDialog::getSaveFileName(0, "Enter filename"); + QString html_file = str + ".html"; + + QString md = noteEdit->toPlainText(); + + QString html; + md_html( + md.toUtf8().constData(), md.length(), + [](const MD_CHAR *html, MD_SIZE html_size, void *userdata) { + QString *htmlPtr = static_cast(userdata); + QString htmlStr(QString::fromUtf8(reinterpret_cast(html), html_size)); + *htmlPtr += htmlStr; + }, + &html, 0, 0); + + QFile file(html_file); + if (file.open(QIODevice::WriteOnly)) { + QTextStream stream(&file); + stream << html; + file.close(); + qDebug() << "File saved successfully at" << filePath; + } else { + qDebug() << "Error", "Failed to open file for writing."; + } + // qDebug() << html; } void MainWindow::loadNotes() From b3d174b19c146adc6f284e6f5aa9304b070dfe60 Mon Sep 17 00:00:00 2001 From: Nighty3098 Date: Sun, 5 May 2024 17:33:04 +0700 Subject: [PATCH 4/5] Edited --- src/CodeKeeper/settingsFunc/functional.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeKeeper/settingsFunc/functional.cpp b/src/CodeKeeper/settingsFunc/functional.cpp index f649391f..d6f192fd 100644 --- a/src/CodeKeeper/settingsFunc/functional.cpp +++ b/src/CodeKeeper/settingsFunc/functional.cpp @@ -76,7 +76,7 @@ void SettingsWindow::saveData() void SettingsWindow::fopenFolder() { - QString str = QFileDialog::getExistingDirectory(0, "Select a directory"); + QString str = QFileDialog::getExistingDirectory(this, "Select Folder"); if (!str.isEmpty()) { qDebug() << str; globalSettings->setValue("path", str); From 128fb288ca7afcfba35d6d7855b7af91c1b35e68 Mon Sep 17 00:00:00 2001 From: Nighty3098 Date: Sun, 5 May 2024 20:11:02 +0700 Subject: [PATCH 5/5] Edited --- src/CodeKeeper/keeperFunc/notesFunc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CodeKeeper/keeperFunc/notesFunc.cpp b/src/CodeKeeper/keeperFunc/notesFunc.cpp index 5e6589c9..1621ee90 100644 --- a/src/CodeKeeper/keeperFunc/notesFunc.cpp +++ b/src/CodeKeeper/keeperFunc/notesFunc.cpp @@ -61,9 +61,8 @@ void MainWindow::exportNoteToHtml() file.close(); qDebug() << "File saved successfully at" << filePath; } else { - qDebug() << "Error", "Failed to open file for writing."; + qDebug() << "Error, Failed to open file for writing."; } - // qDebug() << html; } void MainWindow::loadNotes()