Skip to content

Commit 26fc80a

Browse files
committed
CODA-Q: Migrate recent documents to common/RecentFiles
- Replace qt/RecentDocuments with common/RecentFiles - Centralize cross-platform recent file handling - Remove doctype filtering in File tab backstage view - Show recent files for all document types always Signed-off-by: codewithvk <[email protected]> Change-Id: I0ab0bb31c95c5c5a133a57f9430a1b08e9927aa5
1 parent 68e279d commit 26fc80a

File tree

6 files changed

+32
-194
lines changed

6 files changed

+32
-194
lines changed

browser/src/control/Control.BackstageView.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,18 @@ class BackstageView extends window.L.Class {
595595

596596
const fileName = doc.name || (lastSlashIndex >= 0 ? fullPath.slice(lastSlashIndex + 1) : fullPath);
597597
const filePath = lastSlashIndex >= 0 ? fullPath.slice(0, lastSlashIndex + 1) : '/';
598-
598+
599+
if (!doc.doctype) {
600+
const ext = fileName.split('.').pop()?.toLowerCase() || '';
601+
if (['ods', 'ots', 'xls', 'xlsx', 'csv', 'fods'].includes(ext)) {
602+
doc.doctype = 'calc';
603+
} else if (['odp', 'otp', 'ppt', 'pptx', 'fodp'].includes(ext)) {
604+
doc.doctype = 'impress';
605+
} else {
606+
doc.doctype = 'writer'; // Default
607+
}
608+
}
609+
599610
return {
600611
fileName,
601612
filePath,

qt/DBusService.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
#include "Log.hpp"
1515
#include "LibreOfficeKit/LibreOfficeKit.h"
1616
#include "qt.hpp"
17-
#include "RecentDocuments.hpp"
17+
#include "common/RecentFiles.hpp"
1818
#include <Poco/URI.h>
1919
#include <Poco/Path.h>
2020
#include <QDBusConnection>
2121
#include <QDBusInterface>
2222
#include <QDBusReply>
2323
#include <QDBusConnectionInterface>
24+
#include <QFileInfo>
2425

2526
constexpr const char* SERVICE_NAME = "com.collaboraoffice.Office";
2627
constexpr const char* OBJECT_PATH = "/com/collaboraoffice/Office";
2728

29+
extern RecentFiles recentFiles;
30+
2831
namespace coda
2932
{
3033
void openFiles(const QStringList& files)
@@ -44,7 +47,9 @@ namespace coda
4447
WebView* webViewInstance = new WebView(Application::getProfile());
4548
webViewInstance->load(fileURL);
4649

47-
RecentDocuments::add(file);
50+
QFileInfo fileInfo(file);
51+
Poco::URI uri(Poco::Path(fileInfo.absoluteFilePath().toStdString()));
52+
recentFiles.add(uri.toString());
4853
}
4954
}
5055

qt/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cmake_list= \
4444
../common/Util-mobile.cpp \
4545
../common/Util-unix.cpp \
4646
../common/Uri.cpp \
47+
../common/RecentFiles.cpp \
4748
../kit/ChildSession.cpp \
4849
../kit/DeltaSimd.c \
4950
../kit/Kit.cpp \
@@ -79,7 +80,7 @@ if X86
7980
coda_qt_CXXFLAGS += -mno-direct-extern-access
8081
endif
8182

82-
coda_qt_SOURCES = coda-qt.cpp WebView.cpp DBusService.cpp RecentDocuments.cpp $(BUILT_SOURCES) $(cmake_list)
83+
coda_qt_SOURCES = coda-qt.cpp WebView.cpp DBusService.cpp $(BUILT_SOURCES) $(cmake_list)
8384

8485
metainfodir = $(datadir)/metainfo
8586
metainfo_DATA = com.collaboraoffice.Office.metainfo.xml

qt/RecentDocuments.cpp

Lines changed: 0 additions & 152 deletions
This file was deleted.

qt/RecentDocuments.hpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

qt/coda-qt.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "FileUtil.hpp"
2222
#include "qt.hpp"
2323
#include "DBusService.hpp"
24-
#include "RecentDocuments.hpp"
24+
#include "common/RecentFiles.hpp"
2525

2626
#include <Poco/MemoryStream.h>
2727
#include <Poco/JSON/Parser.h>
@@ -93,6 +93,7 @@ const int SHOW_JS_MAXLEN = 300;
9393
int coolwsd_server_socket_fd = -1;
9494
static COOLWSD* coolwsd = nullptr;
9595
static std::thread coolwsdThread;
96+
RecentFiles recentFiles;
9697
QWebEngineProfile* Application::globalProfile = nullptr;
9798

9899
static const char* getUserName()
@@ -606,7 +607,7 @@ bool Bridge::saveDocument(const std::string& savePath)
606607
if (FileUtil::copyAtomic(tempPath, savePath, false))
607608
{
608609
LOG_INF("Successfully saved file to location: " << savePath);
609-
RecentDocuments::add(QString::fromStdString(savePath));
610+
recentFiles.add(Poco::URI(Poco::Path(savePath)).toString());
610611
_pendingSave = false;
611612
return true;
612613
}
@@ -887,18 +888,8 @@ QVariant Bridge::cool(const QString& messageStr)
887888
}
888889
else if (message == "GETRECENTDOCS")
889890
{
890-
LibreOfficeKitDocumentType docType = LOK_DOCTYPE_TEXT;
891-
lok::Document* loKitDoc = DocumentData::get(_document._appDocId).loKitDocument;
892-
if (loKitDoc) {
893-
docType = static_cast<LibreOfficeKitDocumentType>(loKitDoc->getDocumentType());
894-
}
895-
896-
Poco::JSON::Array::Ptr recentDocs = RecentDocuments::getForAppType(docType);
897-
std::ostringstream jsonStream;
898-
recentDocs->stringify(jsonStream);
899-
QString result = QString::fromStdString(jsonStream.str());
900-
901-
LOG_TRC_NOFILE("GETRECENTDOCS: returning " << recentDocs->size() << " documents for app type");
891+
QString result = QString::fromStdString(recentFiles.serialise());
892+
LOG_TRC_NOFILE("GETRECENTDOCS: returning recent documents");
902893
return result;
903894
}
904895
else if (message.starts_with(CLIPBOARDSET))
@@ -1274,6 +1265,12 @@ int main(int argc, char** argv)
12741265

12751266
Application::initialize();
12761267

1268+
// Initialize recent files
1269+
QString configDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
1270+
QDir().mkpath(configDir + "/Collabora");
1271+
QString recentFilesPath = configDir + "/Collabora/RecentDocuments.conf";
1272+
recentFiles.load(recentFilesPath.toStdString(), 15);
1273+
12771274
// register DBus service and object
12781275
DBusService* dbusService = new DBusService(&app);
12791276
DBusService::registerService(dbusService);

0 commit comments

Comments
 (0)