Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
loader.cc File Reference
#include "loader.hh"
#include <cstdio>
#include <boost/filesystem.hpp>
#include <scroom/threadpool.hh>
#include "callbacks.hh"
#include "pluginmanager.hh"
Include dependency graph for loader.cc:

Classes

class  GObjectUnref< T >
 
class  GtkFileFilterInfoDeleter
 
class  GtkFileFilterListDestroyer
 
class  ScroomInterfaceImpl
 

Typedefs

using GtkFileFilterInfoPtr = std::unique_ptr< GtkFileFilterInfo, GtkFileFilterInfoDeleter >
 

Functions

void destroyGtkFileFilterList (std::list< GtkFileFilter * > &l)
 
char * charpFromString (const std::string &s)
 
GtkFileFilterInfoPtr filterInfoFromPath (const std::string &filename)
 
bool filterMatchesInfo (GtkFileFilterInfo const &info, std::list< GtkFileFilter * > const &filters)
 
void create (NewPresentationInterface *interface)
 
PresentationInterface::Ptr loadPresentation (const std::string &filename)
 
PresentationInterface::Ptr loadPresentation (GtkFileFilterInfo const &info)
 
PresentationInterface::Ptr loadPresentation (GtkFileFilterInfoPtr const &info)
 
void load (GtkFileFilterInfo const &info)
 
void load (GtkFileFilterInfoPtr const &info)
 
void load (const std::string &filename)
 

Typedef Documentation

◆ GtkFileFilterInfoPtr

using GtkFileFilterInfoPtr = std::unique_ptr<GtkFileFilterInfo, GtkFileFilterInfoDeleter>

Function Documentation

◆ charpFromString()

char * charpFromString ( const std::string &  s)
88{
89 const size_t n = s.size();
90 std::unique_ptr<char[]> result(new char[n + 1]);
91 if(!result)
92 {
93 throw std::bad_alloc();
94 }
95
96 strncpy(result.get(), s.c_str(), n + 1);
97 if(result[n] != 0)
98 {
99 throw std::length_error("String size changed during copying");
100 }
101
102 return result.release();
103}
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94
BitmapSurface::Ptr const s
Definition transformpresentation_test.cc:70

Referenced by filterInfoFromPath().

Here is the caller graph for this function:

◆ create()

void create ( NewPresentationInterface interface)
173{
174 PresentationInterface::Ptr const presentation = interface->createNew();
175 if(presentation)
176 {
177 on_presentation_created(presentation);
178 find_or_create_scroom(presentation);
179 }
180 else
181 {
182 throw std::invalid_argument("Unable to create requested presentation");
183 }
184}
void on_presentation_created(const PresentationInterface::Ptr &presentation)
Definition callbacks.cc:634
void find_or_create_scroom(const PresentationInterface::Ptr &presentation)
Definition callbacks.cc:487
virtual PresentationInterface::Ptr createNew()=0
std::shared_ptr< PresentationInterface > Ptr
Definition presentationinterface.hh:73

Referenced by on_new_activate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroyGtkFileFilterList()

void destroyGtkFileFilterList ( std::list< GtkFileFilter * > &  l)
43{
44 while(!l.empty())
45 {
46 GtkFileFilter* f = l.front();
47 g_object_ref_sink(f);
48 g_object_unref(f);
49 l.pop_front();
50 }
51}
PageList const l
Definition compression-tests.cc:33
f
Definition gtkhelper-tests.cc:43

◆ filterInfoFromPath()

GtkFileFilterInfoPtr filterInfoFromPath ( const std::string &  filename)
106{
107 GtkFileFilterInfoPtr filterInfo;
108
109 std::unique_ptr<GFile, GObjectUnref<GFile>> const file(g_file_new_for_path(filename.c_str()));
110 std::unique_ptr<GFileInfo, GObjectUnref<GFileInfo>> const fileInfo(
111 g_file_query_info(file.get(), "standard::*", G_FILE_QUERY_INFO_NONE, nullptr, nullptr)
112 );
113 if(fileInfo)
114 {
115 // g_file_info_get_name(fileInfo) doesn't provide path info.
116 // charpFromString might throw.
117 std::unique_ptr<gchar> filenameCopy(charpFromString(filename));
118 std::unique_ptr<gchar> mime_type(charpFromString(g_content_type_get_mime_type(g_file_info_get_content_type(fileInfo.get()))));
119 std::unique_ptr<gchar> display_name(charpFromString(g_file_info_get_display_name(fileInfo.get())));
120
121 filterInfo.reset(new GtkFileFilterInfo()); // filterInfo->filename uninitialized, so a delete is dangerous
122
123 filterInfo->filename = filenameCopy.release();
124 filterInfo->mime_type = mime_type.release();
125 filterInfo->display_name = display_name.release();
126 filterInfo->contains =
127 static_cast<GtkFileFilterFlags>(GTK_FILE_FILTER_FILENAME | GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE);
128 }
129 else
130 {
131 throw std::invalid_argument("No fileinfo for file " + filename);
132 }
133
134 return filterInfo;
135}
char * charpFromString(const std::string &s)
Definition loader.cc:87
std::unique_ptr< GtkFileFilterInfo, GtkFileFilterInfoDeleter > GtkFileFilterInfoPtr
Definition loader.cc:40

Referenced by load(), and loadPresentation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filterMatchesInfo()

bool filterMatchesInfo ( GtkFileFilterInfo const &  info,
std::list< GtkFileFilter * > const &  filters 
)
138{
139 for(auto const& f: filters)
140 {
141 if(gtk_file_filter_filter(f, &info))
142 {
143 return true;
144 }
145 }
146 return false;
147}

Referenced by load(), and loadPresentation().

Here is the caller graph for this function:

◆ load() [1/3]

void load ( const std::string &  filename)
272{ load(filterInfoFromPath(filename)); }
GtkFileFilterInfoPtr filterInfoFromPath(const std::string &filename)
Definition loader.cc:105
void load(GtkFileFilterInfo const &info)
Definition loader.cc:235
Here is the call graph for this function:

◆ load() [2/3]

void load ( GtkFileFilterInfo const &  info)
236{
237 const auto pm = PluginManager::getInstance();
238 const auto& openPresentationInterfaces = pm->getOpenPresentationInterfaces();
239 const auto& openInterfaces = pm->getOpenInterfaces();
240
241 for(auto const& cur: openPresentationInterfaces)
242 {
243 std::list<GtkFileFilter*> filters = cur.first->getFilters();
244 GtkFileFilterListDestroyer const destroyer(filters);
245 if(filterMatchesInfo(info, filters))
246 {
247 PresentationInterface::Ptr const presentation = cur.first->open(info.filename);
248 if(presentation)
249 {
250 on_presentation_created(presentation);
251 find_or_create_scroom(presentation);
252 return;
253 }
254 }
255 }
256 for(auto const& cur: openInterfaces)
257 {
258 std::list<GtkFileFilter*> filters = cur.first->getFilters();
259 GtkFileFilterListDestroyer const destroyer(filters);
260 if(filterMatchesInfo(info, filters))
261 {
262 cur.first->open(info.filename, ScroomInterfaceImpl::instance());
263 return;
264 }
265 }
266
267 throw std::invalid_argument("Don't know how to open file " + std::string(info.filename));
268}
Definition loader.cc:54
static PluginManager::Ptr getInstance()
Definition pluginmanager.cc:334
static Ptr instance()
Definition loader.cc:276
bool filterMatchesInfo(GtkFileFilterInfo const &info, std::list< GtkFileFilter * > const &filters)
Definition loader.cc:137

Referenced by load(), load(), on_done_loading_plugins(), on_open_activate(), onDragDataReceived(), anonymous_namespace{tiledbitmappresentation.cc}::OpenTiledBitmapAsPresentation::open(), Pnm::open(), and Tiff::open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load() [3/3]

void load ( GtkFileFilterInfoPtr const &  info)
270{ load(*info); }
Here is the call graph for this function:

◆ loadPresentation() [1/3]

PresentationInterface::Ptr loadPresentation ( const std::string &  filename)
187{
188 return loadPresentation(*filterInfoFromPath(filename));
189}
PresentationInterface::Ptr loadPresentation(const std::string &filename)
Definition loader.cc:186

Referenced by loadPresentation(), loadPresentation(), and on_done_loading_plugins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPresentation() [2/3]

PresentationInterface::Ptr loadPresentation ( GtkFileFilterInfo const &  info)
192{
193 static std::map<boost::filesystem::path, PresentationInterface::WeakPtr> loadedPresentations;
194 // Create canonical path from filename
195 const std::map<OpenPresentationInterface::Ptr, std::string>& openPresentationInterfaces =
196 PluginManager::getInstance()->getOpenPresentationInterfaces();
197
198#ifdef HAVE_BOOST_FILESYSTEM_CANONICAL
199 boost::filesystem::path key(canonical(boost::filesystem::path(info.filename)));
200#else
201 boost::filesystem::path const key(absolute(boost::filesystem::path(info.filename)));
202#endif
203
204 PresentationInterface::Ptr presentation = loadedPresentations[key].lock();
205
206 if(!presentation)
207 {
208 for(auto const& cur: openPresentationInterfaces)
209 {
210 std::list<GtkFileFilter*> const filters = cur.first->getFilters();
211 if(filterMatchesInfo(info, filters))
212 {
213 presentation = cur.first->open(info.filename);
214
215 if(presentation)
216 {
217 loadedPresentations[key] = presentation;
218 on_presentation_created(presentation);
219 break;
220 }
221 }
222 }
223 }
224
225 if(presentation)
226 {
227 return presentation;
228 }
229
230 throw std::invalid_argument("Don't know how to load presentation " + std::string(info.filename));
231}
Here is the call graph for this function:

◆ loadPresentation() [3/3]

PresentationInterface::Ptr loadPresentation ( GtkFileFilterInfoPtr const &  info)
233{ return loadPresentation(*info); }
Here is the call graph for this function: