diff --git a/data/Notes.pc.in b/data/Notes.pc.in new file mode 100644 index 0000000..0eb72f0 --- /dev/null +++ b/data/Notes.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +exec_prefix=${prefix} +libdir=${exec_prefix}/lib + +Name: Notes +Description: DeforaOS Desktop Notes library +Version: @VERSION@ +Requires: libDesktop +Cflags: -I${includedir} +Libs: -L${libdir} @RPATH@ -lNotes diff --git a/data/pkgconfig.sh b/data/pkgconfig.sh new file mode 100755 index 0000000..bbb503e --- /dev/null +++ b/data/pkgconfig.sh @@ -0,0 +1,198 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2011-2022 Pierre Pronchery +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +#variables +CONFIGSH="${0%/pkgconfig.sh}/../config.sh" +PREFIX="/usr/local" +DEVNULL="/dev/null" +PROGNAME="pkgconfig.sh" +#executables +DEBUG="_debug" +INSTALL="install" +MKDIR="mkdir -m 0755 -p" +RM="rm -f" +SED="sed" + +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + + +#functions +#pkgconfig +_pkgconfig() +{ + #check the variables + if [ -z "$PACKAGE" ]; then + _error "The PACKAGE variable needs to be set" + return $? + fi + if [ -z "$VERSION" ]; then + _error "The VERSION variable needs to be set" + return $? + fi + [ -z "$BINDIR" ] && BINDIR="$PREFIX/bin" + [ -z "$DATADIR" ] && DATADIR="$PREFIX/share" + [ -z "$INCLUDEDIR" ] && INCLUDEDIR="$PREFIX/include" + [ -z "$LIBDIR" ] && LIBDIR="$PREFIX/lib" + [ -z "$LIBEXECDIR" ] && LIBEXECDIR="$PREFIX/libexec" + [ -z "$MANDIR" ] && MANDIR="$DATADIR/man" + [ -z "$SBINDIR" ] && SBINDIR="$PREFIX/sbin" + if [ -z "$SYSCONFDIR" ]; then + SYSCONFDIR="$PREFIX/etc" + [ "$PREFIX" = "/usr" ] && SYSCONFDIR="/etc" + fi + PKGCONFIG="$PREFIX/lib/pkgconfig" + + while [ $# -gt 0 ]; do + target="$1" + shift + + #clean + [ "$clean" -ne 0 ] && continue + + #uninstall + if [ "$uninstall" -eq 1 ]; then + $DEBUG $RM -- "$PKGCONFIG/$target" || return 2 + continue + fi + + #install + if [ "$install" -eq 1 ]; then + source="${target#$OBJDIR}" + $DEBUG $MKDIR -- "$PKGCONFIG" || return 2 + mode="-m 0644" + basename="$source" + if [ "${source##*/}" != "$source" ]; then + basename="${source##*/}" + fi + $DEBUG $INSTALL $mode "$target" "$PKGCONFIG/$basename" \ + || return 2 + continue + fi + + #portability + RPATH= + if [ "$PREFIX" != "/usr" ]; then + RPATH="-Wl,-rpath-link,\${libdir} -Wl,-rpath,\${libdir}" + case $(uname -s) in + "Darwin") + RPATH="-Wl,-rpath,\${libdir}" + ;; + "SunOS") + RPATH="-Wl,-R\${libdir}" + ;; + esac + fi + + #create + source="${target#$OBJDIR}" + source="${source}.in" + ([ -z "$OBJDIR" ] || $DEBUG $MKDIR -- "${target%/*}") \ + || return 2 + $DEBUG $SED -e "s;@VENDOR@;$VENDOR;g" \ + -e "s;@PACKAGE@;$PACKAGE;g" \ + -e "s;@VERSION@;$VERSION;g" \ + -e "s;@PREFIX@;$PREFIX;g" \ + -e "s;@BINDIR@;$BINDIR;g" \ + -e "s;@DATADIR@;$DATADIR;g" \ + -e "s;@INCLUDEDIR@;$INCLUDEDIR;g" \ + -e "s;@LIBDIR@;$LIBDIR;g" \ + -e "s;@LIBEXECDIR@;$LIBEXECDIR;g" \ + -e "s;@MANDIR@;$MANDIR;g" \ + -e "s;@PWD@;$PWD;g" \ + -e "s;@RPATH@;$RPATH;g" \ + -e "s;@SBINDIR@;$SBINDIR;g" \ + -e "s;@SYSCONFDIR@;$SYSCONFDIR;g" \ + -- "$source" > "$target" + if [ $? -ne 0 ]; then + $RM -- "$target" 2> "$DEVNULL" + return 2 + fi + done + return 0 +} + + +#debug +_debug() +{ + echo "$@" 1>&3 + "$@" +} + + +#error +_error() +{ + echo "$PROGNAME: $@" 1>&2 + return 2 +} + + +#usage +_usage() +{ + echo "Usage: $PROGNAME [-c|-i|-u][-P prefix] target..." 1>&2 + return 1 +} + + +#main +clean=0 +install=0 +uninstall=0 +while getopts "ciuO:P:" name; do + case $name in + c) + clean=1 + ;; + i) + uninstall=0 + install=1 + ;; + u) + install=0 + uninstall=1 + ;; + O) + export "${OPTARG%%=*}"="${OPTARG#*=}" + ;; + P) + PREFIX="$OPTARG" + ;; + ?) + _usage + exit $? + ;; + esac +done +shift $(($OPTIND - 1)) +if [ $# -lt 1 ]; then + _usage + exit $? +fi + +exec 3>&1 +_pkgconfig "$@" diff --git a/data/project.conf b/data/project.conf index 4d95de6..2404255 100644 --- a/data/project.conf +++ b/data/project.conf @@ -1,4 +1,13 @@ -dist=Makefile,deforaos-notes.desktop +targets=Notes.pc +dist=Makefile,Notes.pc.in,deforaos-notes.desktop,pkgconfig.sh +#targets +[Notes.pc] +type=script +script=./pkgconfig.sh +depends=Notes.pc.in,../config.sh +install= + +#dist [deforaos-notes.desktop] install=$(PREFIX)/share/applications diff --git a/include/Notes.h b/include/Notes.h new file mode 100644 index 0000000..8a0450a --- /dev/null +++ b/include/Notes.h @@ -0,0 +1,66 @@ +/* $Id$ */ +/* Copyright (c) 2015-2024 Pierre Pronchery */ +/* This file is part of DeforaOS Desktop Notes */ +/* All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + + + +#ifndef DESKTOP_NOTES_H +# define DESKTOP_NOTES_H + +# include + + +/* Notes */ +/* types */ +typedef struct _Notes Notes; + +typedef enum _NotesColumn +{ + ND_COL_NOTE = 0, + ND_COL_TITLE, + ND_COL_CATEGORY +} NotesColumn; +# define ND_COL_LAST ND_COL_CATEGORY +# define ND_COL_COUNT (ND_COL_LAST + 1) + + +/* functions */ +Notes * notes_new(GtkWidget * window, GtkAccelGroup * group); +void notes_delete(Notes * notes); + +/* accessors */ +GtkWidget * notes_get_view(Notes * notes); +GtkTreeViewColumn * notes_get_view_column(Notes * notes, unsigned int i); +GtkWidget * notes_get_widget(Notes * notes); + +/* useful */ +void notes_about(Notes * notes); +int notes_error(Notes * notes, char const * message, int ret); + +void notes_show_preferences(Notes * notes, gboolean show); + +#endif /* !DESKTOP_NOTES_H */ diff --git a/include/project.conf b/include/project.conf new file mode 100644 index 0000000..0477773 --- /dev/null +++ b/include/project.conf @@ -0,0 +1,6 @@ +includes=Notes.h +dist=Makefile + +#includes +[Notes.h] +install=$(INCLUDEDIR)/Desktop diff --git a/project.conf b/project.conf index 221dd91..99f7956 100644 --- a/project.conf +++ b/project.conf @@ -2,7 +2,7 @@ package=Notes version=0.2.0 config=h,sh -subdirs=data,doc,po,src,tools,tests +subdirs=data,doc,include,po,src,tools,tests targets=tests dist=Makefile,COPYING,config.h,config.sh diff --git a/src/notes.c b/src/notes.c index a108a71..3b7ccee 100644 --- a/src/notes.c +++ b/src/notes.c @@ -57,13 +57,6 @@ static char const _license[] = "All rights reserved.\n" /* Notes */ /* private */ /* types */ -typedef enum _NotesColumn -{ - ND_COL_NOTE, ND_COL_TITLE, ND_COL_CATEGORY -} NotesColumn; -#define ND_COL_LAST ND_COL_CATEGORY -#define ND_COL_COUNT (ND_COL_LAST + 1) - struct _Notes { GtkWidget * window; @@ -260,6 +253,22 @@ void notes_delete(Notes * notes) /* accessors */ +/* notes_get_view */ +GtkWidget * notes_get_view(Notes * notes) +{ + return notes->view; +} + + +/* notes_get_view_column */ +GtkTreeViewColumn * notes_get_view_column(Notes * notes, unsigned int i) +{ + if(i >= 0 && i <= ND_COL_LAST) + return notes->columns[i]; + return NULL; +} + + /* notes_get_widget */ GtkWidget * notes_get_widget(Notes * notes) { diff --git a/src/notes.h b/src/notes.h index 0588616..5348878 100644 --- a/src/notes.h +++ b/src/notes.h @@ -31,29 +31,13 @@ #ifndef NOTES_NOTES_H # define NOTES_NOTES_H +# include "../include/Notes.h" # include "note.h" -# include /* Notes */ -/* types */ -typedef struct _Notes Notes; - - /* functions */ -Notes * notes_new(GtkWidget * window, GtkAccelGroup * group); -void notes_delete(Notes * notes); - -/* accessors */ -GtkWidget * notes_get_widget(Notes * notes); - -/* useful */ -void notes_about(Notes * notes); -int notes_error(Notes * notes, char const * message, int ret); - -void notes_show_preferences(Notes * notes, gboolean show); - -/* notes */ +/* note */ Note * notes_note_add(Notes * notes, Note * note); void notes_note_delete_selected(Notes * notes); void notes_note_remove_all(Notes * notes); diff --git a/src/project.conf b/src/project.conf index beb16d5..0a214b3 100644 --- a/src/project.conf +++ b/src/project.conf @@ -1,31 +1,36 @@ -targets=notes +targets=libNotes,notes +cppflags_force=-I../include #cppflags=-D EMBEDDED cflags_force=`pkg-config --cflags libDesktop` -cflags=-W -Wall -g -O2 -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector +cflags=-W -Wall -g -O2 -D_FORTIFY_SOURCE=2 -fstack-protector ldflags_force=`pkg-config --libs libDesktop` -lintl ldflags=-pie -Wl,-z,relro -Wl,-z,now dist=Makefile,note.h,noteedit.h,notes.h,window.h #targets +[libNotes] +type=library +sources=note.c,noteedit.c,notes.c,window.c +cflags=-fPIC +install=$(LIBDIR) + [notes] type=binary -sources=note.c,noteedit.c,notes.c,window.c,main.c +sources=main.c +depends=libNotes$(SOEXT) +cflags=-fPIE +ldflags=-L. -Wl,-rpath,$(LIBDIR) -lNotes install=$(BINDIR) #sources [main.c] -depends=note.h,notes.h,../config.h +depends=../include/Notes.h,note.h,notes.h,../config.h [note.c] depends=note.h -cflags=-fPIC - -[noteedit.c] -cflags=-fPIC [notes.c] -depends=note.h,notes.h,../config.h -cflags=-fPIC +depends=../include/Notes.h,note.h,notes.h,../config.h [window.c] -depends=notes.h,window.h +depends=../include/Notes.h,notes.h,window.h diff --git a/tools/notes.c b/tools/notes.c index 3755032..b602a4e 100644 --- a/tools/notes.c +++ b/tools/notes.c @@ -28,15 +28,9 @@ -#ifndef EMBEDDED -# define EMBEDDED -#endif #include #include - -#include "../src/note.c" -#include "../src/noteedit.c" -#include "../src/notes.c" +#include "Notes.h" /* Notes */ @@ -87,6 +81,7 @@ static MailerPlugin * _notes_init(MailerPluginHelper * helper) { NotesPlugin * notes; GtkWidget * widget; + GtkTreeViewColumn * column; size_t i; if((notes = malloc(sizeof(*notes))) == NULL) @@ -100,12 +95,13 @@ static MailerPlugin * _notes_init(MailerPluginHelper * helper) notes->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); widget = notes_get_widget(notes->notes); gtk_box_pack_start(GTK_BOX(notes->widget), widget, TRUE, TRUE, 0); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(notes->notes->view), - FALSE); + widget = notes_get_view(notes->notes); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(widget), FALSE); for(i = 0; i < ND_COL_COUNT; i++) - if(notes->notes->columns[i] != NULL && i != ND_COL_TITLE) - gtk_tree_view_column_set_visible(notes->notes->columns[i], - FALSE); + if((column = notes_get_view_column(notes->notes, i)) == NULL) + continue; + else if(i != ND_COL_TITLE) + gtk_tree_view_column_set_visible(column, FALSE); gtk_widget_show_all(notes->widget); return notes; } diff --git a/tools/project.conf b/tools/project.conf index a4c8a83..ce05bef 100644 --- a/tools/project.conf +++ b/tools/project.conf @@ -1,4 +1,5 @@ targets=notes +cppflags=-I../include cflags_force=`pkg-config --cflags libDesktop Mailer` -fPIC cflags=-W -Wall -g -O2 -D_FORTIFY_SOURCE=2 -fstack-protector ldflags_force=`pkg-config --libs libDesktop` @@ -9,6 +10,7 @@ dist=Makefile [notes] type=plugin sources=notes.c +ldflags=-L../src -Wl,-rpath,$(LIBDIR) -lNotes install=$(LIBDIR)/Mailer/plugins #sources