summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2010-11-21 13:36:22 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2010-11-21 13:36:22 +0200
commit5ad35ab766d5aa4f85f11f7bbcfda39f3dec8ed1 (patch)
tree4414f83e51b2f2905af938b030ae882c88713d0b /src
parent48214f18a489487aa7051f0f8e41b76b5a38af77 (diff)
* mu-msg-prio.[ch]: add implementation
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/mu-msg-prio.c65
-rw-r--r--src/mu-msg-prio.h63
3 files changed, 124 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2e9a835..48c5641 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,7 @@ libmu_la_SOURCES= \
mu-msg-fields.h \
mu-msg-flags.c \
mu-msg-flags.h \
+ mu-msg-prio.c \
mu-msg-prio.h \
mu-msg-status.h \
mu-msg.c \
diff --git a/src/mu-msg-prio.c b/src/mu-msg-prio.c
new file mode 100644
index 0000000..7e40660
--- /dev/null
+++ b/src/mu-msg-prio.c
@@ -0,0 +1,65 @@
+/*
+** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+**
+** 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; either version 3, or (at your option) any
+** later version.
+**
+** 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, write to the Free Software Foundation,
+** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**
+*/
+
+#include "mu-msg-prio.h"
+
+
+const char*
+mu_msg_prio_name (MuMsgPrio prio)
+{
+ switch (prio) {
+ case MU_MSG_PRIO_LOW : return "low";
+ case MU_MSG_PRIO_NORMAL : return "normal";
+ case MU_MSG_PRIO_HIGH : return "high";
+ default : g_return_val_if_reached (NULL);
+ }
+}
+
+MuMsgPrio
+mu_msg_prio_from_char (char k)
+{
+ switch (k) {
+ case 'l': return MU_MSG_PRIO_LOW;
+ case 'n': return MU_MSG_PRIO_NORMAL;
+ case 'h': return MU_MSG_PRIO_HIGH;
+ default: g_return_val_if_reached (MU_MSG_PRIO_NONE);
+ }
+}
+
+char
+mu_msg_prio_to_char (MuMsgPrio prio)
+{
+ switch (prio) {
+ case MU_MSG_PRIO_LOW : return 'l';
+ case MU_MSG_PRIO_NORMAL : return 'n';
+ case MU_MSG_PRIO_HIGH : return 'h';
+ default : g_return_val_if_reached (0);
+ }
+}
+
+
+void
+mu_msg_prio_foreach (MuMsgPrioForeachFunc func, gpointer user_data)
+{
+ g_return_if_fail (func);
+
+ func (MU_MSG_PRIO_LOW, user_data);
+ func (MU_MSG_PRIO_NORMAL, user_data);
+ func (MU_MSG_PRIO_HIGH, user_data);
+}
diff --git a/src/mu-msg-prio.h b/src/mu-msg-prio.h
index caddc66..187141f 100644
--- a/src/mu-msg-prio.h
+++ b/src/mu-msg-prio.h
@@ -20,13 +20,66 @@
#ifndef __MU_MSG_PRIO_H__
#define __MU_MSG_PRIO_H__
-enum _MuMsgPrio {
- MU_MSG_PRIO_NONE = 0,
+#include <glib.h>
- MU_MSG_PRIO_LOW = 1,
- MU_MSG_PRIO_NORMAL = 2,
- MU_MSG_PRIO_HIGH = 3
+G_BEGIN_DECLS
+
+enum _MuMsgPrio {
+ MU_MSG_PRIO_LOW,
+ MU_MSG_PRIO_NORMAL,
+ MU_MSG_PRIO_HIGH
};
typedef enum _MuMsgPrio MuMsgPrio;
+static const MuMsgPrio MU_MSG_PRIO_NONE = (MuMsgPrio)-1;
+
+
+/**
+ * get a printable name for the message priority
+ * (ie., MU_MSG_PRIO_LOW=>"low" etc.)
+ *
+ * @param prio a message priority
+ *
+ * @return a printable name for this priority
+ */
+const char* mu_msg_prio_name (MuMsgPrio prio) G_GNUC_CONST;
+
+
+/**
+ * get the MuMsgPriority corresponding to a one-character shortcut
+ * ('l'=>MU_MSG_PRIO_, 'n'=>MU_MSG_PRIO_NORMAL or
+ * 'h'=>MU_MSG_PRIO_HIGH)
+ *
+ * @param k a character
+ *
+ * @return a message priority
+ */
+MuMsgPrio mu_msg_prio_from_char (char k) G_GNUC_CONST;
+
+
+/**
+ * get the one-character shortcut corresponding to a message priority
+ * ('l'=>MU_MSG_PRIO_, 'n'=>MU_MSG_PRIO_NORMAL or
+ * 'h'=>MU_MSG_PRIO_HIGH)
+ *
+ * @param prio a mesage priority
+ *
+ * @return a shortcut character or 0 in case of error
+ */
+char mu_msg_prio_to_char (MuMsgPrio prio) G_GNUC_CONST;
+
+
+typedef void (*MuMsgPrioForeachFunc) (MuMsgPrio prio, gpointer user_data);
+/**
+ * call a function for each message priority
+ *
+ * @param func a callback function
+ * @param user_data a user pointer to pass to the callback
+ */
+void mu_msg_prio_foreach (MuMsgPrioForeachFunc func, gpointer user_data);
+
+
+
+G_END_DECLS
+
#endif /*__MU_MSG_PRIO_H__*/