Commit 9444a117 authored by Osama Ahmad's avatar Osama Ahmad Committed by Thomas Holder
Browse files

Simplified ResourceManager. It does only one thing: fix broken links.

ResourceManager doesn't have any member variable. Only one
function and only does one thing: fix broken links.
There is no need for having a singleton that gets initialized,
for having constructors, destructors and virtual functions.
Replaced with a single function "Inkscape::fixBrokenLinks".
parent 3997e317
......@@ -55,7 +55,7 @@
#include "helper/action-context.h"
#include "helper/action.h" //sp_action_perform
#include "io/resource-manager.h"
#include "io/fix-broken-links.h"
#include "object/sp-namedview.h"
#include "object/sp-root.h"
......@@ -153,7 +153,6 @@ SPDesktop::init (SPNamedView *nv, Inkscape::UI::Widget::Canvas *acanvas, SPDeskt
// Temporary workaround for link order issues:
Inkscape::DeviceManager::getManager().getDevices();
Inkscape::ResourceManager::getManager();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
_guides_message_context = std::unique_ptr<Inkscape::MessageContext>(new Inkscape::MessageContext(messageStack()));
......
......@@ -48,7 +48,6 @@
#include "path-prefix.h"
#include "print.h"
#include "rdf.h"
#include "selection-chemistry.h"
#include "verbs.h"
#include "extension/db.h"
......@@ -56,11 +55,9 @@
#include "extension/input.h"
#include "extension/output.h"
#include "helper/png-write.h"
#include "io/file.h"
#include "io/resource.h"
#include "io/resource-manager.h"
#include "io/fix-broken-links.h"
#include "io/sys.h"
#include "object/sp-defs.h"
......@@ -69,7 +66,6 @@
#include "object/sp-use.h"
#include "style.h"
#include "ui/dialog/font-substitution.h"
#include "ui/dialog/filedialog.h"
#include "ui/interface.h"
#include "ui/tools/tool-base.h"
......
......@@ -23,26 +23,26 @@
#include "inkscape-application.h"
#include "inkscape-window.h"
#include "auto-save.h" // Auto-save
#include "desktop.h" // Access to window
#include "file.h" // sp_file_convert_dpi
#include "inkscape.h" // Inkscape::Application
#include "auto-save.h" // Auto-save
#include "desktop.h" // Access to window
#include "file.h" // sp_file_convert_dpi
#include "inkscape.h" // Inkscape::Application
#include "include/glibmm_version.h"
#include "inkgc/gc-core.h" // Garbage Collecting init
#include "debug/logger.h" // INKSCAPE_DEBUG_LOG support
#include "inkgc/gc-core.h" // Garbage Collecting init
#include "debug/logger.h" // INKSCAPE_DEBUG_LOG support
#include "io/file.h" // File open (command line).
#include "io/resource.h" // TEMPLATE
#include "io/resource-manager.h" // Fix up references.
#include "io/file.h" // File open (command line).
#include "io/resource.h" // TEMPLATE
#include "io/fix-broken-links.h" // Fix up references.
#include "object/sp-root.h" // Inkscape version.
#include "object/sp-root.h" // Inkscape version.
#include "ui/interface.h" // sp_ui_error_dialog
#include "ui/interface.h" // sp_ui_error_dialog
#include "ui/dialog/startup.h"
#include "ui/dialog/font-substitution.h" // Warn user about font substitution.
#include "ui/shortcuts.h" // Shortcuts... init
#include "ui/shortcuts.h" // Shortcuts... init
#include "widgets/desktop-widget.h" // Close without saving dialog
#include "ui/dialog/dialog-manager.h" // save state
......@@ -325,7 +325,7 @@ InkscapeApplication::document_fix(InkscapeWindow* window)
SPDocument* document = window->get_document();
// Perform a fixup pass for hrefs.
if ( Inkscape::ResourceManager::getManager().fixupBrokenLinks(document) ) {
if ( Inkscape::fixBrokenLinks(document) ) {
Glib::ustring msg = _("Broken links have been changed to point to existing files.");
SPDesktop* desktop = window->get_desktop();
if (desktop != nullptr) {
......
......@@ -15,18 +15,15 @@
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <cerrno>
#include <unistd.h>
#include <map>
#include <glibmm/fileutils.h>
#include <glibmm/regex.h>
#include <gtkmm/icontheme.h>
#include <gtkmm/messagedialog.h>
#include <glib/gstdio.h>
#include <glibmm/i18n.h>
#include <glibmm/miscutils.h>
#include <glibmm/convert.h>
......@@ -49,19 +46,15 @@
#include "helper/action-context.h"
#include "io/resource.h"
#include "io/resource-manager.h"
#include "io/fix-broken-links.h"
#include "io/sys.h"
#include "libnrtype/FontFactory.h"
#include "object/sp-root.h"
#include "object/sp-style-elem.h"
#include "svg/svg-color.h"
#include "object/sp-root.h"
#include "object/sp-style-elem.h"
#include "ui/dialog/debug.h"
#include "ui/tools/tool-base.h"
......@@ -234,8 +227,6 @@ Application::Application(bool use_gui) :
Inkscape::DeviceManager::getManager().loadConfig();
}
Inkscape::ResourceManager::getManager();
/* set language for user interface according setting in preferences */
Glib::ustring ui_language = prefs->getString("/ui/language");
if(!ui_language.empty())
......
......@@ -5,7 +5,7 @@ set(io_SRC
file.cpp
file-export-cmd.cpp
resource.cpp
resource-manager.cpp
fix-broken-links.cpp
stream/bufferstream.cpp
stream/gzipstream.cpp
stream/inkscapestream.cpp
......@@ -21,7 +21,7 @@ set(io_SRC
file.h
file-export-cmd.h
resource.h
resource-manager.h
fix-broken-links.h
stream/bufferstream.h
stream/gzipstream.h
stream/inkscapestream.h
......
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Inkscape::ResourceManager - tracks external resources such as image and css files.
* tracks external resources such as image and css files.
*
* Copyright 2011 Jon A. Cruz <jon@joncruz.org>
*
......@@ -19,7 +19,7 @@
#include <glibmm/uriutils.h>
#include <glibmm/convert.h>
#include "resource-manager.h"
#include "fix-broken-links.h"
#include "document.h"
#include "document-undo.h"
......@@ -106,62 +106,47 @@ static std::string convertPathToRelative( std::string const &path, std::string c
}
class ResourceManagerImpl : public ResourceManager {
public:
ResourceManagerImpl();
~ResourceManagerImpl() override;
bool fixupBrokenLinks(SPDocument *doc) override;
bool fixBrokenLinks(SPDocument *doc);
/**
* Walk all links in a document and create a listing of unique broken links.
*
* @return a list of all broken links.
*/
std::vector<Glib::ustring> findBrokenLinks(SPDocument *doc);
/**
* Resolve broken links as a whole and return a map for those that can be found.
*
* Note: this will allow for future enhancements including relinking to new locations
* with the most broken files found, etc.
*
* @return a map of found links.
*/
std::map<Glib::ustring, Glib::ustring> locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks);
/**
* Try to parse href into a local filename using standard methods.
*
* @return true if successful.
*/
bool extractFilepath(Glib::ustring const &href, std::string &filename);
/**
* Try to parse href into a local filename using some non-standard methods.
* This means the href is likely invalid and should be rewritten.
*
* @return true if successful.
*/
bool reconstructFilepath(Glib::ustring const &href, std::string &filename);
bool searchUpwards( std::string const &base, std::string const &subpath, std::string &dest );
protected:
};
ResourceManagerImpl::ResourceManagerImpl()
: ResourceManager()
{
}
/**
* Walk all links in a document and create a listing of unique broken links.
*
* @return a list of all broken links.
*/
static std::vector<Glib::ustring> findBrokenLinks(SPDocument *doc);
/**
* Resolve broken links as a whole and return a map for those that can be found.
*
* Note: this will allow for future enhancements including relinking to new locations
* with the most broken files found, etc.
*
* @return a map of found links.
*/
static std::map<Glib::ustring, Glib::ustring> locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks);
/**
* Try to parse href into a local filename using standard methods.
*
* @return true if successful.
*/
static bool extractFilepath(Glib::ustring const &href, std::string &filename);
/**
* Try to parse href into a local filename using some non-standard methods.
* This means the href is likely invalid and should be rewritten.
*
* @return true if successful.
*/
static bool reconstructFilepath(Glib::ustring const &href, std::string &filename);
static bool searchUpwards( std::string const &base, std::string const &subpath, std::string &dest );
ResourceManagerImpl::~ResourceManagerImpl()
= default;
bool ResourceManagerImpl::extractFilepath(Glib::ustring const &href, std::string &filename)
static bool extractFilepath(Glib::ustring const &href, std::string &filename)
{
bool isFile = false;
......@@ -191,7 +176,7 @@ bool ResourceManagerImpl::extractFilepath(Glib::ustring const &href, std::string
return isFile;
}
bool ResourceManagerImpl::reconstructFilepath(Glib::ustring const &href, std::string &filename)
static bool reconstructFilepath(Glib::ustring const &href, std::string &filename)
{
bool isFile = false;
......@@ -211,7 +196,7 @@ bool ResourceManagerImpl::reconstructFilepath(Glib::ustring const &href, std::st
}
std::vector<Glib::ustring> ResourceManagerImpl::findBrokenLinks( SPDocument *doc )
static std::vector<Glib::ustring> findBrokenLinks( SPDocument *doc )
{
std::vector<Glib::ustring> result;
std::set<Glib::ustring> uniques;
......@@ -249,7 +234,7 @@ std::vector<Glib::ustring> ResourceManagerImpl::findBrokenLinks( SPDocument *doc
}
std::map<Glib::ustring, Glib::ustring> ResourceManagerImpl::locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks)
static std::map<Glib::ustring, Glib::ustring> locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks)
{
std::map<Glib::ustring, Glib::ustring> result;
......@@ -323,7 +308,7 @@ std::map<Glib::ustring, Glib::ustring> ResourceManagerImpl::locateLinks(Glib::us
return result;
}
bool ResourceManagerImpl::fixupBrokenLinks(SPDocument *doc)
bool fixBrokenLinks(SPDocument *doc)
{
bool changed = false;
if ( doc ) {
......@@ -387,8 +372,7 @@ bool ResourceManagerImpl::fixupBrokenLinks(SPDocument *doc)
return changed;
}
bool ResourceManagerImpl::searchUpwards( std::string const &base, std::string const &subpath, std::string &dest )
static bool searchUpwards( std::string const &base, std::string const &subpath, std::string &dest )
{
bool exists = false;
// TODO debug g_message("............");
......@@ -418,23 +402,6 @@ bool ResourceManagerImpl::searchUpwards( std::string const &base, std::string co
return exists;
}
static ResourceManagerImpl* theInstance = nullptr;
ResourceManager::ResourceManager()
= default;
ResourceManager::~ResourceManager() = default;
ResourceManager& ResourceManager::getManager() {
if ( !theInstance ) {
theInstance = new ResourceManagerImpl();
}
return *theInstance;
}
} // namespace Inkscape
/*
......
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Inkscape::ResourceManager - Manages external resources such as image and css files.
* Manages external resources such as image and css files.
*
* Copyright 2011 Jon A. Cruz <jon@joncruz.org>
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_INKSCAPE_RESOURCE_MANAGER_H
#define SEEN_INKSCAPE_RESOURCE_MANAGER_H
class SPDocument;
namespace Inkscape {
class ResourceManager {
public:
static ResourceManager& getManager();
virtual bool fixupBrokenLinks(SPDocument *doc) = 0;
protected:
ResourceManager();
virtual ~ResourceManager();
private:
ResourceManager(ResourceManager const &) = delete; // no copy
void operator=(ResourceManager const &) = delete; // no assign
};
} // namespace Inkscape
bool fixBrokenLinks(SPDocument *doc);
#endif // SEEN_INKSCAPE_RESOURCE_MANAGER_H
}
/*
Local Variables:
......
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