summaryrefslogtreecommitdiff
path: root/RealtimeSync/resources.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:00:17 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:00:17 +0200
commitfd0853d2623dd278b08288331ed42e3be59252fb (patch)
treea7645daeaef8bdbed064faf4eb88e72cee58726c /RealtimeSync/resources.cpp
parent2.1 (diff)
downloadFreeFileSync-fd0853d2623dd278b08288331ed42e3be59252fb.tar.gz
FreeFileSync-fd0853d2623dd278b08288331ed42e3be59252fb.tar.bz2
FreeFileSync-fd0853d2623dd278b08288331ed42e3be59252fb.zip
2.2
Diffstat (limited to 'RealtimeSync/resources.cpp')
-rw-r--r--RealtimeSync/resources.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/RealtimeSync/resources.cpp b/RealtimeSync/resources.cpp
new file mode 100644
index 00000000..638df0f6
--- /dev/null
+++ b/RealtimeSync/resources.cpp
@@ -0,0 +1,81 @@
+#include "resources.h"
+#include <wx/wfstream.h>
+#include <wx/zipstrm.h>
+#include <wx/image.h>
+#include <wx/icon.h>
+#include "../shared/globalFunctions.h"
+#include "../shared/standardPaths.h"
+
+
+const GlobalResources& GlobalResources::getInstance()
+{
+ static GlobalResources instance;
+ return instance;
+}
+
+
+GlobalResources::GlobalResources()
+{
+ //map, allocate and initialize pictures
+ bitmapResource[wxT("start red.png")] = (bitmapStart = new wxBitmap(wxNullBitmap));
+ bitmapResource[wxT("add pair.png")] = (bitmapAddFolderPair = new wxBitmap(wxNullBitmap));
+ bitmapResource[wxT("remove pair.png")] = (bitmapRemoveFolderPair = new wxBitmap(wxNullBitmap));
+
+ programIcon = new wxIcon(wxNullIcon);
+}
+
+
+GlobalResources::~GlobalResources()
+{
+ //free bitmap resources
+ for (std::map<wxString, wxBitmap*>::iterator i = bitmapResource.begin(); i != bitmapResource.end(); ++i)
+ delete i->second;
+
+ //free other resources
+ delete programIcon;
+}
+
+
+void GlobalResources::load() const
+{
+ wxFFileInputStream input(FreeFileSync::getInstallationDir() + globalFunctions::FILE_NAME_SEPARATOR + wxT("Resources.dat"));
+ if (input.IsOk()) //if not... we don't want to react too harsh here
+ {
+ //activate support for .png files
+ wxImage::AddHandler(new wxPNGHandler); //ownership passed
+
+ wxZipInputStream resourceFile(input);
+
+ std::map<wxString, wxBitmap*>::iterator bmp;
+ while (true)
+ {
+ std::auto_ptr<wxZipEntry> entry(resourceFile.GetNextEntry());
+ if (entry.get() == NULL)
+ break;
+
+ const wxString name = entry->GetName();
+
+ //search if entry is available in map
+ if ((bmp = bitmapResource.find(name)) != bitmapResource.end())
+ *(bmp->second) = wxBitmap(wxImage(resourceFile, wxBITMAP_TYPE_PNG));
+ }
+ }
+
+#ifdef FFS_WIN
+ *programIcon = wxIcon(wxT("A_PROGRAM_ICON"));
+#else
+#include "RealtimeSync.xpm"
+ *programIcon = wxIcon(RealtimeSync_xpm);
+#endif
+}
+
+
+const wxBitmap& GlobalResources::getImageByName(const wxString& imageName) const
+{
+ std::map<wxString, wxBitmap*>::const_iterator bmp = bitmapResource.find(imageName);
+ if (bmp != bitmapResource.end())
+ return *bmp->second;
+ else
+ return wxNullBitmap;
+}
+
bgstack15