mirror of https://github.com/djcb/mu.git
* mu-msg-prio.[ch]: add implementation
This commit is contained in:
parent
48214f18a4
commit
5ad35ab766
|
@ -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 \
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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__*/
|
||||
|
|
Loading…
Reference in New Issue