Ejemplo n.º 1
0
int main( int argc, char* argv[] )
{
	Glib::RefPtr<Gtk::Application> app =
		Gtk::Application::create( argc, argv, "org.gtkmm.examples.base" );

	TransparentWindow window;
	win = &window;
	window.set_type_hint( Gdk::WINDOW_TYPE_HINT_DOCK );
	window.set_keep_below( true );
	window.set_decorated( false );
	window.set_default_size( 200, 200 );
	window.maximize();

	screen = window.get_screen();
	gtk_widget_set_visual( GTK_WIDGET( window.gobj() ),
			screen->get_rgba_visual()->gobj() );

	css = Gtk::CssProvider::create();
	css->load_from_path( "style.css" );
	Gtk::StyleContext::add_provider_for_screen( screen, css,
			GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );

	NoteCollection notes;
	notes.addNote( *new Note( "Silverstone", "6 Hours of Silverstone",
			Glib::DateTime::create_local( 2014, 4, 20, 0, 0, 0.0 ) ) );
	notes.addNote( *new Note( "Spa", "6 Hours of Spa-Francorchamps",
			Glib::DateTime::create_local( 2014, 5, 3, 0, 0, 0.0 ) ) );

	notes.addNote( *new Note( "Today", "is now!",
			Glib::DateTime::create_now_local() ) );

	notes.addNote( *new Note( "Pre-Alpha",
				"is a state myorg isn't in have yet." ) );

	YearView view;
	view.setNotes( &notes );
	view.updateNotes();

	window.add( view );
	window.show_all();

	window.get_window()->set_events( Gdk::BUTTON_RELEASE_MASK );
	window.signal_button_release_event().connect(
			sigc::ptr_fun( buttonReleased ) );
	
	return app->run(window);
}
Ejemplo n.º 2
0
void NoteReader::go(FILE* inputStream) {
    
    NoteStore noteStore;
    
    std::string command;
    
    while (!feof(inputStream)) {
        command = Util::readNextLine(inputStream);
        
        if (strcmp(command.c_str(), "CREATE") == 0 || strcmp(command.c_str(), "UPDATE") == 0) {
            Note note = Util::readXml(inputStream, "</note>");
            noteStore.updateNote(note);
        }
        if (strcmp(command.c_str(), "DELETE") == 0) {
            std::string guid = Util::readNextLine(inputStream);
            noteStore.deleteNote(guid);
        }
        if (strcmp(command.c_str(), "SEARCH") == 0) {
            std::string term = Util::readNextLine(inputStream);
            NoteCollection noteCollection = noteStore.search(term);
            std::vector<Note> notes = noteCollection.getNotes();
            if (notes.size() == 0) {
                std::cout << "\n";
            } else {
                std::string results = "";
                for (std::vector<Note>::iterator note = notes.begin() ; note != notes.end(); ++note) {
                    results += note->getGuid() + ",";
                }
                std::string output = results.substr(0,results.length()-1);
                std::cout << output << "\n";
            }
            
        }
        
    }
}
Ejemplo n.º 3
0
NoteCollection NoteStore::search(std::string term) {
    
    std::transform(term.begin(), term.end(), term.begin(), ::tolower);
    
    std::string word = "";
    std::vector<std::string> words;
    
    for (unsigned int i=0; i<term.length(); i++) {
        char c = term[i];
        if (c != ' ') {
            word += c;
        } else {
            if (word.length() > 0) {
                words.push_back(word);
            }
            word = "";
        }
    }
    if (word.length() > 0) {
        words.push_back(word);
    }
    
    NoteCollection noteCollection;
    Note note;
    std::string guid;
    
    for ( auto it = this->noteDatabase.begin(); it != this->noteDatabase.end(); ++it ) {
        
        guid = it->first;
        note = it->second;
        
        bool matchesAll = true;
        
        for (unsigned int i=0; i<words.size(); i++) {
            std::string keyword = words[i];
            long wildcardAt = keyword.find_first_of('*');
            
            if (strcmp(keyword.substr(0, 4).c_str(), "tag:") == 0) {
                if (!note.hasTag(keyword.substr(4,keyword.length()-4),wildcardAt-4)) {
                    matchesAll = false;
                    break;
                }
            } else if (strcmp(keyword.substr(0, 8).c_str(), "created:") == 0) {
                if (!note.createdOnOrAfter(keyword.substr(8,keyword.length()-8))) {
                    matchesAll = false;
                    break;
                }
            } else {
                if (!note.hasKeyword(keyword, wildcardAt)) {
                    matchesAll = false;
                    break;
                }
            }
        }
        
        if (matchesAll) {
            noteCollection.addNote(note);
        }
    }
    
    noteCollection.sortByDate();
    return noteCollection;
    
}