82 KitList(
const string dbname,
const string user,
const string port,
bool verbose =
false);
85 void add_item(
const string name);
86 void add_item(
const string name,
long cat_id);
87 void append_items_to_category(
long from_cat_id,
long to_cat_id,
item_choice choice);
88 void associate_item_with_category(
long id,
long cat_id);
89 void list_items_start(
bool empty_list);
90 void list_item(
Item& item);
91 void list_items_end(
bool empty_list,
size_t count);
93 bool on_list_item(
Item& item);
100 void list_categories();
101 void new_category(
const string name);
102 void delete_category(
long id);
103 void delete_item(
long id);
104 void remove_item_from_category(
long id,
long cat_id);
105 void set_item_flag(
long id);
106 void unset_item_flag(
long id);
107 void set_category_flag(
long id);
108 void unset_category_flag(
long id);
109 void set_all_flags();
110 void unset_all_flags();
122 cout << right << item.
get_id()
126 <<
'\t' <<
" (" << (item.
get_checked() ?
"Yn" :
"yN") <<
"q): ";
128 bool checked =
false;
130 if (s ==
"y" || s ==
"Y") {
132 }
else if (s ==
"n" || s ==
"N") {
134 }
else if (s ==
"q" || s ==
"Q") {
139 m_changed.push_back(&item);
164 m_dao =
new XmlDao(verbose);
166 m_dao =
new KitListPgsqlDao(dbname, user, port, verbose);
186 long id = m_dao->add_item(name, cat_id);
187 cout <<
"Added item with id " <<
id <<
" to category " << cat_id << endl << endl;
189 long id = m_dao->add_item(name);
190 cout <<
"Added item with id " <<
id << endl << endl;
204 m_dao->append_items_to_category(to_cat_id, from_cat_id, choice);
215 m_dao->associate_item_with_category(
id, cat_id);
216 cout <<
"Associated item " <<
id <<
" with category " << cat_id << endl << endl;
240 cout <<
"<html>" << endl
242 <<
"<title>Items</title>" << endl
248 cout <<
"<table cellpadding=\"3\" cellspacing=\"0\" border=\"1\">" << endl
249 <<
"<tr><th>ID</th><th>Description</th></tr>" << endl;
252 cout << right <<
"ID" <<
"\tDescription" << endl;
253 cout << right <<
"======" <<
"\t===========" << endl;
272 cout <<
"</table>" << endl;
276 cout <<
"<p>" << count <<
" items</p>" << endl
277 <<
"</body>" << endl <<
"</html>" << endl;
281 cout << count <<
" items" << endl << endl;
294 cout <<
"<tr><td>" << item.
get_id() <<
"</td>" 319 list_items_start(items.empty());
320 for (
ItemIter i = items.begin(); i != items.end(); ++i ) {
323 list_items_end(items.empty(), items.size());
338 Category* cat = m_dao->get_category(cat_id, choice);
344 for (
ItemIter i = items->begin(); i != items->end(); ++i) {
357 for (
ItemIter i = items.begin(); i != items.end(); ++i) {
371 m_dao->update_item_checked_state(changed);
382 m_dao->update_item_checked_state(changed);
396 Category* cat = m_dao->get_category(cat_id, choice);
402 for (
ItemIter i = items->begin(); i != items->end(); ++i) {
414 m_dao->delete_item(
id);
415 cout <<
"Deleted item with id " <<
id << endl << endl;
426 m_dao->remove_item_from_category(
id, cat_id);
427 cout <<
"Removed item " <<
id <<
" from category " << cat_id << endl << endl;
436 m_dao->delete_category(
id);
437 cout <<
"Deleted category with id " <<
id << endl << endl;
451 cout <<
"<html>" << endl
453 <<
"<title>Categories</title>" << endl
459 cout <<
"<table cellpadding=\"3\" cellspacing=\"0\" border=\"1\">" << endl
460 <<
"<tr><th>ID</th><th>Description</th></tr>" << endl;
463 cout << right <<
"ID" <<
"\tDescription" << endl;
464 cout << right <<
"======" <<
"\t===========" << endl;
468 cout <<
"<tr><td>" << (*i)->get_id() <<
"</td>" 469 <<
"<td>" << (*i)->get_name() <<
"</td></tr>" << endl;
472 cout << (*i)->get_id()
473 <<
"\t" << (*i)->get_name() << endl;
479 cout <<
"</table>" << endl;
483 cout <<
"<p>" << c.size() <<
" categories</p>" << endl
484 <<
"</body>" << endl <<
"</html>" << endl;
488 cout << c.size() <<
" categories" << endl << endl;
497 long id = m_dao->new_category(name);
498 cout <<
"Added category id " <<
id <<
" named \"" << name <<
'"' << endl << endl;
506 m_dao->set_item_flag(
id);
507 cout <<
"Checked item with id " <<
id << endl << endl;
515 m_dao->unset_item_flag(
id);
516 cout <<
"Unchecked items with id " <<
id << endl << endl;
524 m_dao->set_category_flag(
id);
525 cout <<
"Checked items with category id " <<
id << endl << endl;
533 m_dao->unset_category_flag(
id);
534 cout <<
"Unchecked items with category id " <<
id << endl << endl;
542 m_dao->set_all_flags();
543 cout <<
"Checked all items" << endl << endl;
551 m_dao->unset_all_flags();
552 cout <<
"Unchecked all items" << endl << endl;
559 int main(
int argc,
char **argv) {
560 setlocale(LC_CTYPE,
"");
564 bindtextdomain(GETTEXT_PACKAGE, PROGRAMNAME_LOCALEDIR);
565 bind_textdomain_codeset(GETTEXT_PACKAGE,
"UTF-8");
566 textdomain(GETTEXT_PACKAGE);
572 int option_index = 0;
573 int invalid_opt =
false;
575 long dest_cat_n = -1;
596 enum actions action = NOP;
599 static struct option long_options[] = {
601 {
"port", required_argument, 0,
'p'},
604 {
"force", no_argument, &force_flag, 1},
605 {
"add", required_argument, 0,
'a'},
606 {
"add-to-category", no_argument, 0,
'A'},
607 {
"category", required_argument, 0,
'c'},
608 {
"copy-to-category", required_argument, 0,
'C'},
609 {
"only-unchecked", no_argument, 0,
'k'},
610 {
"only-checked", no_argument, 0,
'K'},
611 {
"item", required_argument, 0,
'i'},
612 {
"list", no_argument, 0,
'l'},
613 {
"list-checked", no_argument, 0,
'X'},
614 {
"list-unchecked", no_argument, 0,
'U'},
615 {
"list-categories", no_argument, 0,
'q'},
616 {
"tick-unchecked", no_argument, 0,
't'},
617 {
"tick-checked", no_argument, 0,
'T'},
618 {
"new-category", required_argument, 0,
'n'},
619 {
"delete", no_argument, 0,
'd'},
620 {
"set", no_argument, 0,
'x'},
621 {
"clear", no_argument, 0,
'u'},
622 {
"set-all", no_argument, 0,
's'},
623 {
"clear-all", no_argument, 0,
'z'},
624 {
"interactive", no_argument, 0,
'g'},
628 {
"help", no_argument, 0,
'h'},
629 {
"version", no_argument, 0,
'v'},
633 c = getopt_long(argc, argv,
"hvVHp:fa:Ac:C:i:lXUqtTn:dxuszkKg",
634 long_options, &option_index);
636 c = getopt_long(argc, argv,
"hvV",
637 long_options, &option_index);
651 cout <<
"Usage:" << endl
653 <<
" " << argv[0] <<
" [OPTIONS] [DBNAME [USERNAME]]" << endl << endl
655 <<
" " << argv[0] <<
" [FILENAME]" << endl << endl
657 <<
"Options:" << endl
658 <<
" -h, --help\t\t\t\tshow this help, then exit" << endl
659 <<
" -v, --version\t\t\t\tshow version information, then exit" << endl
660 <<
" -V, --verbose\t\t\t\tverbose output" << endl
662 <<
" -g, --interactive\t\t\tDisplay interactive GUI" << endl
663 <<
" -p, --port=PORT\t\tspecify the port to connect to, default 5432" << endl
664 <<
" -a, --add=NAME\t\t\tcreate item named NAME," << endl
665 <<
" \t\t\tif -c specified, associates item with that category" << endl
666 <<
" -A, --add-to-category\t\tadd existing item to category" << endl
667 <<
" \t\t\t\t\tboth -i and -c must be specified" << endl
668 <<
" -l, --list\t\t\t\tlist all items, limit to category, if -c specified" << endl
669 <<
" -X, --list-checked\t\tsame as -l, except only checked items" << endl
670 <<
" -U, --list-unchecked\t\tsame as -l, except only unchecked items" << endl
671 <<
" -T, --tick-checked\t\tinteratively choose to tick/untick checked items" << endl
672 <<
" -t, --tick-unchecked\t\tinteratively choose to tick/untick unchecked items" << endl
673 <<
" -q, --list-categories\t\tlist categories" << endl
674 <<
" -n, --new-category=CATEGORY\tcreate category named CATEGORY" << endl
675 <<
" -c, --category=NUMBER\t\tspecify category number for action" << endl
676 <<
" -C, --copy-to-category=NUMBER\t\tcopy all or specific category to" << endl
677 <<
" \t\t\t\t\tcategory NUMBER. Specify source category with -c" << endl
678 <<
" \t\t\t\t\tor omit to copy all items" << endl
679 <<
" -k, --only-unchecked\t\tWhen using -C, operate on unchecked items only" << endl
680 <<
" -K, --only-checked\t\tWhen using -C, operate on checked items only" << endl
681 <<
" -i, --item=NUMBER\t\t\tspecify item number for action" << endl
682 <<
" -d, --delete\t\t\t\tdelete category or item specified by -c or -i, if" << endl
683 <<
" \t\t\t\t\tboth -i and -c are specifed, simply removes the " << endl
684 <<
" \t\t\t\t\tassociation between them" << endl
685 <<
" -x, --set\t\t\t\t\tset flag for item specified by -i" << endl
686 <<
" -u, --clear\t\t\t\tclear flag for item specified by -i" << endl
687 <<
" -s, --set-all\t\t\t\tsets all flags" << endl
688 <<
" -z, --clear-all\t\t\tclears all flags" << endl
689 <<
" -H, --html\t\t\t\thtml formatted output" << endl
695 cout <<
"kitlist " << VERSION << endl;
711 item_n = strtol(optarg, NULL, 0);
714 cat_n = strtol(optarg, NULL, 0);
718 dest_cat_n = strtol(optarg, NULL, 0);
725 action = ASSOCIATE_ITEM;
731 action = LIST_CHECKED;
734 action = LIST_UNCHECKED;
737 action = TICK_CHECKED;
740 action = TICK_UNCHECKED;
743 action = LIST_CATEGORIES;
747 action = NEW_CATEGORY;
795 string dbname = (index < argc) ? argv[index++] :
"";
796 string user = (index < argc) ? argv[index++] :
"";
802 action = (argc == 1) ? SHOW_GUI : action;
813 if (cat_n >= 0 || force_flag) {
816 cerr <<
"Specify -f (--force) to copy all items to a category" << endl << endl;
820 if (item_n >= 0 && cat_n >=0) {
823 cerr <<
"You must specify the item and category using -i and -c" << endl << endl;
841 case LIST_CATEGORIES:
848 if (cat_n >= 0 && item_n >=0) {
850 }
else if (item_n >=0) {
856 cerr <<
"Specify -f (--force) to delete a category" << endl << endl;
866 cerr <<
"Specify an item set using -i or --item" << endl << endl;
874 cerr <<
"Specify an item to clear using -i or --item" << endl << endl;
885 cerr <<
"Specify -f (--force) to set all flags" << endl << endl;
896 cerr <<
"Specify -f (--force) to clear all flags" << endl << endl;
907 if (dbname.length() > 0)
908 gui.open_file(dbname);
TickItem(ItemContainer &changed)
void delete_item(long id)
void tick_items(Category &c)
void list_item(Item &item)
Outputs details of the passed item to STDOUT.
void set_category_flag(long id)
virtual bool has_items()
Returns true if there are any items associated with this category.
int main(int argc, char **argv)
ItemContainer::iterator ItemIter
CategoryContainer::iterator CategoryIter
void unset_category_flag(long id)
KitListDao * m_dao
Reference to an implementation DAO class.
void append_items_to_category(long from_cat_id, long to_cat_id, item_choice choice)
Copies items from one category to another.
std::vector< Item * > ItemContainer
void delete_category(long id)
void add_item(const string name)
void foreach_item(const SlotForeachItem &slot)
Executes a callback function for each associated item.
virtual void set_checked(bool checked)
virtual size_t item_count()
Returns the number of items associated with this category.
void execute(ItemContainer &items, ItemFunctor &functor)
void list_items(Category &c)
bool operator()(Item &item)
void unset_item_flag(long id)
void list_items_end(bool empty_list, size_t count)
Called after writing a list of items to STDOUT.
Defines the methods that an implementation of this class must implement.
void set_item_flag(long id)
Encapsulates the methods for the application's GUI front end.
void remove_item_from_category(long id, long cat_id)
void associate_item_with_category(long id, long cat_id)
Associates an existing item with an existing category.
static int verbose_flag
Flag set by `–verbose'.
ItemContainer & m_changed
bool on_list_item(Item &item)
void execute(ItemFunctor &functor)
Executes the passed ItemFunctor.
std::string get_description()
Implementation of a KitListDao using XML as the persistence store.
KitList(const string dbname, const string user, const string port, bool verbose=false)
Constructor specifying Postgresql database connection parameters.
void list_items_start(bool empty_list)
Called before writing a list of items to STDOUT.
std::vector< Category * > CategoryContainer
void new_category(const string name)
void list_categories()
Lists details of all categories to STDOUT.
Functor for processing items.
Business/service layer implementation.
static int html_flag
Flag set by `–html'.