Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsModGalleria.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2006-Today Guy Deleeuw
3 *
4 * See the LICENSE file for terms of use.
5 */
6 
7 #include <dlfcn.h>
8 #include <stdio.h>
9 
10 #include <iostream>
11 
12 #include <Wt/WLogger>
13 #include <Wt/WText>
14 #include <Wt/WTheme>
15 
16 #include <Main/WsApplication.h>
17 #include <Logger/WsLogger.h>
18 
19 #include "WsModGalleria.h"
20 
21 extern "C" {
22  void WsModGalleriaInit(void)
23  {
24  void* hndl = dlopen("libwt.so", RTLD_NOW | RTLD_GLOBAL);
25  if ( hndl == NULL ) {
26  fprintf(stderr, "cannot load libwt.so shared library! %s\n", dlerror());
27  return;
28  }
29  }
30 }
31 
32 using namespace Wt;
33 
34 WsGalleria::WsGalleria(WContainerWidget* parent)
35  : WContainerWidget(parent)
36 { }
37 
39 { }
40 
42 {
43  WContainerWidget::load();
44  setId("galleria");
45  std::string galleriaPath = WApplication::instance()->internalPath();
46  boost::algorithm::replace_last(galleriaPath, "galleria", "ws.res/galleria");
48  std::string fullGalleriaPath = user->getRootPath() + galleriaPath;
49  boost::filesystem::directory_iterator end_itr;
50  for (boost::filesystem::directory_iterator itr_dir(fullGalleriaPath + "/thumbnails"); itr_dir != end_itr; ++itr_dir) {
51  if ( itr_dir->path().extension() == ".jpeg"
52  || itr_dir->path().extension() == ".jpg"
53  || itr_dir->path().extension() == ".png"
54  ) {
55  string img = itr_dir->path().string();
56  boost::replace_first(img, WsApp->docRoot(), ""); // /demo_site/about/ws.res/galleria/thumbnails/img01.png
57  boost::algorithm::replace_all(img, "&", "&amp;");
58  string imgThumb = img;
59  boost::replace_last(imgThumb, "thumbnails", "images"); // /demo_site/about/ws.res/galleria/images/img01.png
60  std::string text = "<a href=\""
61  + img
62  + "\"><img src=\""
63  + imgThumb
64  + "\" data-title=\"My title\" data-description=\"My description\"/></a>";
65  std::cout << text << std::endl;
66  addWidget(new WText(text, Wt::PlainText));
67  }
68  }
69  std::string javaScript = "Galleria.loadTheme('";
70  javaScript += wApp->resourcesUrl();
71  javaScript += "galleria/themes/classic/galleria.classic.min.js'); \n";
72  javaScript += "Galleria.run('#galleria');";
73  WApplication::instance()->doJavaScript(javaScript);
74 }
75 
76 
77 
78 
79 
80 
81 
82 
84  : WsModule()
85 {
86  // Add the required css
87  // WApplication::instance()->useStyleSheet(WApplication::instance()->resourcesUrl() + "webodf/webodf.css");
88  // Add the required javascript file
89  WApplication::instance()->require("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js");
90  WApplication::instance()->require(WApplication::instance()->resourcesUrl() + "galleria/galleria-1.2.9.min.js", "galleria");
91 }
92 
94 {
95 }
96 
97 WWidget* WsModGalleria::createContentsMenuBar(WContainerWidget* parent) const
98 {
99  return 0;
100 }
101 
102 WWidget* WsModGalleria::createContents(WContainerWidget* parent) const
103 {
104  WsGalleria* pcw = new WsGalleria(parent);
105  pcw->setOptions(options());
106  return pcw;
107 }
108 
109 WsEditorWidget* WsModGalleria::createEditor(WContainerWidget* parent) const
110 {
111  return 0;
112 }
113 
114 WWidget* WsModGalleria::createAdmin(WContainerWidget* parent) const
115 {
116  return 0;
117 }
118 
119 std::string WsModGalleria::description() const
120 {
121  return "WsModGalleria wittyShare module";
122 }
123 
WsUser * wsUser()
virtual void load()
static WsApplication * wsInstance()
Facility function to access the application object.
Definition: WsApplication.h:39
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
void WsModGalleriaInit(void)
WsModGalleria()
CTor.
const std::vector< WsOption > & options() const
Get all options.
Definition: WsOption.cpp:70
Interface that provides differents methods for accessing the FsTree as well as other features...
Definition: WsUser.h:33
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
a wittyShare module
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
Definition: WsUser.cpp:55
WsGalleria(Wt::WContainerWidget *parent=0)
#define WsApp
Define a shortcut to the application instance.
Definition: WsApplication.h:62
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Definition: WsOption.cpp:57
std::string description() const
Return the description of the module.
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.