Move the priority titles to a separate file

This commit is contained in:
Pierre Pronchery 2015-04-21 01:23:00 +02:00
parent a23a9accc6
commit e6cd781ba6
4 changed files with 82 additions and 26 deletions

31
src/priority.c Normal file
View File

@ -0,0 +1,31 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Todo */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "priority.h"
#define N_(string) (string)
/* variables */
TodoPriorityTitle priorities[] =
{
{ TODO_PRIORITY_UNKNOWN,N_("Unknown") },
{ TODO_PRIORITY_LOW, N_("Low") },
{ TODO_PRIORITY_MEDIUM, N_("Medium") },
{ TODO_PRIORITY_HIGH, N_("High") },
{ TODO_PRIORITY_URGENT, N_("Urgent") },
{ 0, NULL }
};

35
src/priority.h Normal file
View File

@ -0,0 +1,35 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Todo */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef TODO_PRIORITY_H
# define TODO_PRIORITY_H
# include "todo.h"
/* types */
typedef struct
{
TodoPriority priority;
char const * title;
} TodoPriorityTitle;
/* variables */
extern TodoPriorityTitle priorities[];
#endif /* !TODO_PRIORITY_H */

View File

@ -4,16 +4,19 @@ cflags_force=-W `pkg-config --cflags libDesktop`
cflags=-Wall -g -O2 -pedantic
ldflags_force=`pkg-config --libs libDesktop` -lintl
ldflags=
dist=Makefile,task.h,taskedit.h,todo.h,window.h
dist=Makefile,priority.h,task.h,taskedit.h,todo.h,window.h
[todo]
type=binary
sources=task.c,taskedit.c,todo.c,window.c,main.c
sources=priority.c,task.c,taskedit.c,todo.c,window.c,main.c
install=$(BINDIR)
[main.c]
depends=task.h,todo.h,../config.h
[priority.c]
depends=todo.h,priority.h
[task.c]
depends=task.h
cflags=-fPIC
@ -22,7 +25,7 @@ cflags=-fPIC
cflags=-fPIC
[todo.c]
depends=task.h,todo.h,../config.h
depends=priority.h,task.h,todo.h,../config.h
cflags=-fPIC
[window.c]

View File

@ -32,6 +32,7 @@ static char const _license[] =
#include <gtk/gtk.h>
#include <System.h>
#include <Desktop.h>
#include "priority.h"
#include "taskedit.h"
#include "todo.h"
#include "../config.h"
@ -119,20 +120,6 @@ static const struct
{ 0, NULL, 0, NULL }
};
static const struct
{
unsigned int priority;
char const * title;
} _todo_priorities[] =
{
{ TODO_PRIORITY_UNKNOWN,N_("Unknown") },
{ TODO_PRIORITY_LOW, N_("Low") },
{ TODO_PRIORITY_MEDIUM, N_("Medium") },
{ TODO_PRIORITY_HIGH, N_("High") },
{ TODO_PRIORITY_URGENT, N_("Urgent") },
{ 0, NULL }
};
static char const * _authors[] =
{
@ -240,12 +227,12 @@ static void _new_view(Todo * todo)
G_TYPE_STRING, /* display priority */
G_TYPE_STRING); /* category */
todo->priorities = gtk_list_store_new(2, G_TYPE_UINT, G_TYPE_STRING);
for(i = 0; _todo_priorities[i].title != NULL; i++)
for(i = 0; priorities[i].title != NULL; i++)
{
gtk_list_store_append(todo->priorities, &iter);
gtk_list_store_set(todo->priorities, &iter,
0, _todo_priorities[i].priority,
1, _(_todo_priorities[i].title), -1);
0, priorities[i].priority,
1, _(priorities[i].title), -1);
}
todo->filter = gtk_tree_model_filter_new(GTK_TREE_MODEL(todo->store),
NULL);
@ -485,10 +472,10 @@ Task * todo_task_add(Todo * todo, Task * task)
strftime(completion, sizeof(completion), "%c", &t);
}
priority = task_get_priority(task);
for(i = 0; priority != NULL && _todo_priorities[i].title != NULL; i++)
if(strcmp(_(_todo_priorities[i].title), priority) == 0)
for(i = 0; priority != NULL && priorities[i].title != NULL; i++)
if(strcmp(_(priorities[i].title), priority) == 0)
{
tp = _todo_priorities[i].priority;
tp = priorities[i].priority;
break;
}
gtk_list_store_set(todo->store, &iter, TD_COL_TASK, task,
@ -933,10 +920,10 @@ void todo_task_set_priority(Todo * todo, GtkTreePath * path,
_todo_get_iter(todo, &iter, path);
gtk_tree_model_get(model, &iter, TD_COL_TASK, &task, -1);
task_set_priority(task, priority);
for(i = 0; _todo_priorities[i].title != NULL; i++)
if(strcmp(_(_todo_priorities[i].title), priority) == 0)
for(i = 0; priorities[i].title != NULL; i++)
if(strcmp(_(priorities[i].title), priority) == 0)
{
tp = _todo_priorities[i].priority;
tp = priorities[i].priority;
break;
}
gtk_list_store_set(todo->store, &iter, TD_COL_PRIORITY, tp,