mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merge pull request #164 from kiwix/usb-flash-drive
choose the library.xml file in the binary's directory if it exists
This commit is contained in:
commit
18f0e07116
@ -200,7 +200,7 @@ QString ContentManager::downloadBook(const QString &id)
|
||||
|
||||
void ContentManager::eraseBookFilesFromComputer(const QString fileToRemove)
|
||||
{
|
||||
QString dirName = QString::fromUtf8(getDataDirectory().c_str());
|
||||
QString dirName = KiwixApp::instance()->getLibraryDirectory();
|
||||
QDir dir(dirName, fileToRemove);
|
||||
for(const QString& filename: dir.entryList()) {
|
||||
dir.remove(filename);
|
||||
|
@ -27,6 +27,7 @@ kiwix::Downloader* createDownloader() {
|
||||
|
||||
KiwixApp::KiwixApp(int& argc, char *argv[])
|
||||
: QApplication(argc, argv),
|
||||
m_libraryDirectory(findLibraryDirectory()),
|
||||
m_library(),
|
||||
mp_downloader(createDownloader()),
|
||||
m_manager(&m_library, mp_downloader)
|
||||
@ -109,6 +110,17 @@ KiwixApp::~KiwixApp()
|
||||
delete mp_mainWindow;
|
||||
}
|
||||
|
||||
QString KiwixApp::findLibraryDirectory()
|
||||
{
|
||||
QString currentPathLibrary = QString::fromStdString(appendToDirectory(removeLastPathElement(getExecutablePath()),"library.xml"));
|
||||
QFileInfo libraryFile(currentPathLibrary);
|
||||
|
||||
if (libraryFile.exists())
|
||||
return QString::fromStdString(removeLastPathElement(getExecutablePath()));
|
||||
else
|
||||
return QString::fromStdString(getDataDirectory());
|
||||
}
|
||||
|
||||
KiwixApp *KiwixApp::instance()
|
||||
{
|
||||
return static_cast<KiwixApp*>(QApplication::instance());
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
kiwix::Downloader* getDownloader() { return mp_downloader; }
|
||||
TabBar* getTabWidget() { return mp_tabWidget; }
|
||||
QAction* getAction(Actions action);
|
||||
QString getLibraryDirectory() { return m_libraryDirectory; };
|
||||
|
||||
bool isCurrentArticleBookmarked();
|
||||
|
||||
@ -93,6 +94,7 @@ protected:
|
||||
private:
|
||||
QTranslator m_qtTranslator, m_appTranslator;
|
||||
UrlSchemeHandler m_schemeHandler;
|
||||
QString m_libraryDirectory;
|
||||
Library m_library;
|
||||
kiwix::Downloader* mp_downloader;
|
||||
ContentManager m_manager;
|
||||
@ -102,6 +104,8 @@ private:
|
||||
QErrorMessage* mp_errorDialog;
|
||||
|
||||
QAction* mpa_actions[MAX_ACTION];
|
||||
|
||||
QString findLibraryDirectory();
|
||||
};
|
||||
|
||||
#endif // KIWIXAPP_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "library.h"
|
||||
|
||||
#include "kiwixapp.h"
|
||||
|
||||
#include <kiwix/manager.h>
|
||||
|
||||
@ -25,9 +25,10 @@ Library::Library()
|
||||
{
|
||||
auto manipulator = LibraryManipulator(this);
|
||||
auto manager = kiwix::Manager(&manipulator);
|
||||
qInfo() << QString::fromStdString(getDataDirectory());
|
||||
manager.readFile(appendToDirectory(getDataDirectory(),"library.xml"), false);
|
||||
manager.readBookmarkFile(appendToDirectory(getDataDirectory(),"library.bookmarks.xml"));
|
||||
m_libraryDirectory = KiwixApp::instance()->getLibraryDirectory();
|
||||
qInfo() << m_libraryDirectory;
|
||||
manager.readFile(appendToDirectory(m_libraryDirectory.toStdString(),"library.xml"), false);
|
||||
manager.readBookmarkFile(appendToDirectory(m_libraryDirectory.toStdString(),"library.bookmarks.xml"));
|
||||
qInfo() << getBookIds().length();
|
||||
emit(booksChanged());
|
||||
}
|
||||
@ -131,8 +132,8 @@ void Library::removeBookmark(const QString &zimId, const QString &url)
|
||||
|
||||
void Library::save()
|
||||
{
|
||||
m_library.writeToFile(appendToDirectory(getDataDirectory(),"library.xml"));
|
||||
m_library.writeBookmarksToFile(appendToDirectory(getDataDirectory(), "library.bookmarks.xml"));
|
||||
m_library.writeToFile(appendToDirectory(m_libraryDirectory.toStdString(),"library.xml"));
|
||||
m_library.writeBookmarksToFile(appendToDirectory(m_libraryDirectory.toStdString(), "library.bookmarks.xml"));
|
||||
}
|
||||
|
||||
kiwix::Book &Library::getBookById(QString id)
|
||||
|
@ -47,6 +47,7 @@ signals:
|
||||
private:
|
||||
kiwix::Library m_library;
|
||||
QMap<QString, std::shared_ptr<kiwix::Reader>> m_readersMap;
|
||||
QString m_libraryDirectory;
|
||||
friend class LibraryManipulator;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user