Skip to content

Commit

Permalink
init public repo
Browse files Browse the repository at this point in the history
darcs-hash:20080602035253-a887e-eb8ad83b08a2685e246a076f8dbe42c43276e27e.gz
  • Loading branch information
thjaeger committed Jun 2, 2008
0 parents commit 1ccb0c9
Show file tree
Hide file tree
Showing 40 changed files with 5,914 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
PREFIX = /usr/local
DFLAGS = #-ggdb #-pg
OFLAGS = -Os
AOFLAGS = -O3
CXXFLAGS = -Wall $(DFLAGS) `pkg-config gtkmm-2.4 libglademm-2.4 --cflags`
TARGETS = easystroke
DEFINES =

LIBS = $(DFLAGS) -lboost_serialization -lXtst `pkg-config gtkmm-2.4 libglademm-2.4 gthread-2.0 --cflags --libs`
INCLUDES =

BINARY = easystroke

CCFILES = $(wildcard *.cc) $(wildcard cellrenderertk/*.cc)
OFILES = $(patsubst %.cc,%.o,$(CCFILES)) dsimple.o gui.o cellrenderertk/cellrenderertk.o cellrenderertk/marshalers.o
DEPFILES = $(wildcard *.Po) $(wildcard cellrenderertk/*.Po)
GENFILES = cellrenderertk/marshalers.h cellrenderertk/marshalers.c

all: $(TARGETS)

.PHONY: all clean $(BINARY)

clena: clean

clean:
$(RM) $(OFILES) $(BINARY) $(GENFILES) $(DEPFILES) gui.c gui.o

include $(DEPFILES)

easystroke: $(OFILES)
$(CXX) $(LDFLAGS) -o $(BINARY) $(OFILES) $(LIBS)

stroke.o: stroke.cc
$(CXX) $(CXXFLAGS) $(AOFLAGS) $(DEFINES) $(INCLUDES) -MT $@ -MMD -MP -MF $*.Po -o $@ -c $<

%.o: %.cc
$(CXX) $(CXXFLAGS) $(OFLAGS) $(DEFINES) $(INCLUDES) -MT $@ -MMD -MP -MF $*.Po -o $@ -c $<

gui.c: gui.glade
echo "const char *gui_buffer = \"\\" > gui.c
sed 's/"/\\"/g' gui.glade | sed 's/.*/&\\n\\/' >> gui.c
echo "\";" >> gui.c

cellrenderertk/cellrenderertk.o: cellrenderertk/cellrenderertk.c cellrenderertk/marshalers.h cellrenderertk/marshalers.c
$(CC) -Wall `pkg-config gtk+-2.0 --cflags` cellrenderertk/cellrenderertk.c -o cellrenderertk/cellrenderertk.o -c

cellrenderertk/marshalers.o: cellrenderertk/marshalers.h cellrenderertk/marshalers.c
$(CC) -Wall `pkg-config gtk+-2.0 --cflags` cellrenderertk/marshalers.c -o cellrenderertk/marshalers.o -c

cellrenderertk/marshalers.h: cellrenderertk/marshalers.list
glib-genmarshal --prefix=_gtk_marshal --header cellrenderertk/marshalers.list > cellrenderertk/marshalers.h

cellrenderertk/marshalers.c: cellrenderertk/marshalers.list
glib-genmarshal --prefix=_gtk_marshal --body cellrenderertk/marshalers.list > cellrenderertk/marshalers.c
185 changes: 185 additions & 0 deletions actiondb.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#include "actiondb.h"
#include "main.h"

#include <iostream>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
//#include <boost/serialization/base_object.hpp>

// I don't know WHY I need this, I'm just glad I found out I did...
BOOST_CLASS_EXPORT(StrokeSet)

BOOST_CLASS_EXPORT(Action)
BOOST_CLASS_EXPORT(Command)
BOOST_CLASS_EXPORT(ModAction)
BOOST_CLASS_EXPORT(SendKey)
BOOST_CLASS_EXPORT(Scroll)
BOOST_CLASS_EXPORT(Ignore)

template<class Archive> void Action::serialize(Archive & ar, const unsigned int version) {}

template<class Archive> void Command::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<Action>(*this);
ar & cmd;
}

template<class Archive> void ModAction::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<Action>(*this);
ar & mods;
}

template<class Archive> void SendKey::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<ModAction>(*this);
ar & key;
ar & code;
ar & xtest;
}

template<class Archive> void Scroll::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<ModAction>(*this);
}

template<class Archive> void Ignore::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<ModAction>(*this);
}

template<class Archive> void StrokeSet::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<std::set<RStroke> >(*this);
}

template<class Archive> void StrokeInfo::serialize(Archive & ar, const unsigned int version) {
ar & strokes;
ar & action;
}

using namespace std;

bool Command::run() {
system(cmd.c_str());
return true;
}

inline ostream& operator<<(ostream& output, const Action& c) {
return c.show(output);
}

ActionDB::ActionDB() : filename(config_dir+"actions") {}

void ActionDB::read() {
try {
ifstream ifs(filename.c_str(), ios::binary);
boost::archive::text_iarchive ia(ifs);
ia >> *this;
if (verbosity >= 2)
cout << "Loaded " << strokes.size() << " actions." << endl;
} catch (...) {
cout << "Error: Couldn't read action database." << endl;
}
}

bool ActionDB::write() const {
try {
ofstream ofs(filename.c_str());
boost::archive::text_oarchive oa(ofs);
const ActionDB db = *this;
oa << db;
if (verbosity >= 2)
cout << "Saved " << strokes.size() << " actions." << endl;
return true;
} catch (...) {
cout << "Error: Couldn't save action database." << endl;
return false;
}
}

bool ActionDB::remove(const string& name) {
if (!has(name))
return false;
strokes.erase(name);
return true;
}

bool ActionDB::rename(const string& name, const string& name2) {
if (!has(name))
return false;
if (has(name2))
return false;
strokes[name2] = strokes[name];
strokes.erase(name);
write();
return true;
}

bool ActionDB::addCmd(RStroke stroke, const string& name, const string& cmd) {
if (has(name))
return false;
strokes[name].strokes.clear();
if (stroke)
strokes[name].strokes.insert(stroke);
strokes[name].action = Command::create(cmd);
write();
return true;
}

bool ActionDB::changeCmd(const string& name, const string& cmd) {
RCommand c = boost::dynamic_pointer_cast<Command>(strokes[name].action);
if (c && c->cmd == cmd)
return true;
if (c)
c->cmd = cmd;
else
strokes[name].action = Command::create(cmd);
write();
return true;
}

int ActionDB::nested_size() const {
int size = 0;
for (const_iterator i = begin(); i != end(); i++)
size += i->second.strokes.size();
return size;
}

Ranking ActionDB::handle(RStroke s) {
Ranking r;
r.stroke = s;
r.score = -1;
bool success = false;
if (!s)
return r;
for (StrokeIterator i = strokes_begin(); i; i++) {
if (!i.stroke())
continue;
double score = Stroke::compare(s, i.stroke());
r.r.insert(pair<double, pair<string, RStroke> >(score, pair<string, RStroke>(i.name(), i.stroke())));
if (score >= r.score) {
r.score = score;
if (score >= 0.7) {
r.name = i.name();
r.action = i.action();
success = true;
}
}
}
if (success) {
if (verbosity >= 1)
cout << "Excecuting Action " << r.name << "..." << endl;
if (r.action)
r.action->run();
} else {
if (verbosity >= 1)
cout << "Couldn't find matching stroke." << endl;
}
return r;
}

LActionDB& actions() {
static LActionDB actions_;
return actions_;
}
Loading

0 comments on commit 1ccb0c9

Please sign in to comment.