Browse Source

lazy update

master
John ShaggyTwoDope Jenkins 4 years ago
parent
commit
944838f866
7 changed files with 579 additions and 3 deletions
  1. 157
    0
      adressimport
  2. 3
    3
      backup
  3. 16
    0
      rubyimg.rb
  4. 89
    0
      src/dunstify/Makefile
  5. 0
    0
      src/dunstify/config.mk
  6. BIN
      src/dunstify/dunstify
  7. 314
    0
      src/dunstify/dunstify.c

+ 157
- 0
adressimport View File

@@ -0,0 +1,157 @@
#!/usr/bin/python
# adr_conv.py
#
# Converts a vCard address book into abook addressbook format
#
# Author: Gavin Costello (gavcos@gmail.com)
# Date: 19.02.2009

import optparse

desc="""This program converts a gmail vCard address book into a format readable by abook
(http://abook.sourceforge.net).

To export your gmail contacts in vCard format, select Contacts -> Export and choose the 3rd export format (vCard).

The file will be saved by default as contacts.vcf

"""

parser = optparse.OptionParser(description=desc, version='%prog version 1.0')

parser.add_option('-i', '--inputfile', \
dest='inputfile', action='store', default='contacts.vcf', \
help='The name of the vCard file containing the contacts to convert (default=%default)')
parser.add_option('-o', '--outputfile', \
dest='outputfile', action='store', default='addressbook', \
help='The name of the output file to be generated by this script (default=%default)')
parser.add_option('-d', '--debug', \
dest='debug', action='store_true', default=False,
help='Print debug statements (default=%default)')

(opts, args) = parser.parse_args()

name = ''; # Contact name
phone = ''; # Contact phone
email = ''; # Contact email
nick = ''; # Contact nickname
org = ''; # Contact organisation
note = ''; # Notes
emails = [] # Email list
count = 0; # Contacts count

# Open input file, read-only
try:
cfile = open(opts.inputfile, 'r')
except IOError:
print('Unable to open input file: %s' % opts.inputfile)
raise

# Open output file for writing
try:
ofile = open(opts.outputfile, 'w+')
except IOError:
print('Unable to open output file: %s' % opts.outputfile)
raise

ofile.write('\n')
ofile.write('[format]\n')
ofile.write('program=abook\n')
ofile.write('\n')

# Loop through input file
for line in cfile.readlines():
# Name field
if (line.startswith('FN')):
name = line.split(':')[1].strip()
#name = unicode(name, 'utf-8')
ofile.write('\n')
ofile.write('[%d]\n' % count)
count += 1
if opts.debug:
print(name, end="")
ofile.write('name=%s\n' % name)
elif (line.startswith('EMAIL')):
email = line.split(':')[1].strip()
emails.append(email)
elif (line.startswith('TEL')):
# Verify if it's a fax number
parts = line.split(';')
if (len(parts) > 2): # Fax number
phone = parts[2].split(':')[1]
ofile.write('fax=%s' % phone)
continue

# Normal telephone number
try:
tel = parts[1]
except IndexError: # Phone type not defined (other in gmail)
phone = line.split(':')[1]
ofile.write('mobile=%s' % phone)
continue

fulltype = tel.split('=')[1]
type = fulltype.split(':')[0]
if opts.debug:
print('type=%s' % type,)

phone = line.split(':')[1]
if (type == 'HOME'):
ofile.write('phone=%s' % phone)
if (type == 'CELL'):
ofile.write('mobile=%s' % phone)
if (type == 'WORK'):
ofile.write('workphone=%s' % phone)
elif (line.startswith('NICKNAME')):
# Notes / nicknames
try:
nick = line.split(':')[2].strip()
except IndexError:
nick = line.split(':')[1].strip()
ofile.write('nick=%s\n' % nick,)
elif (line.startswith('ORG')):
org = line.split(':')[1].strip()
if ((name == "") & (org != "")):
ofile.write('name=%s' % org,)
ofile.write('custom1=%s' % org,)
elif (line.startswith('NOTE')):
note = line.split(':')[1].strip()
ofile.write('note=%s\n' % note,)
elif (line.startswith('ADR')):
# Address
adr_parts = line.split(';')[2:]
for i, part in enumerate(adr_parts):
if (part):
if i == 0:
ofile.write('address_lines=%s\n' % part)
if i == 1:
ofile.write('address_lines=%s\n' % part)
if i == 2:
ofile.write('city=%s\n' % part)
if i == 3:
ofile.write('state=%s\n' % part)
if i == 4:
ofile.write('zip=%s\n' % part)
if i == 5:
ofile.write('country=%s\n' % part)
elif (line.startswith('END')):
if (len(emails) > 0):
ofile.write('email=%s\n' % ", ".join(emails),)
emails = []
else:
continue;

print('\n%s contacts processed' % count)

try:
cfile.close()
except IOError:
print('Unable to close input file: %s' % opts.inputfile)
raise
try:
ofile.close()
except IOError:
print('Unable to close output file: %s' % opts.outputfile)
raise

exit(0)

+ 3
- 3
backup View File

@@ -10,11 +10,11 @@ INCLUDE1="/home/shaggy/.vimrc /home/shaggy/.abook /home/shaggy/.calcurse /home/s
INCLUDE2="/home/shaggy/.config/bspwm /home/shaggy/.config/dwb /home/shaggy/.config/htop /home/shaggy/.config/mpd"
INCLUDE3="/home/shaggy/.config/mps-youtube /home/shaggy/.config/mpv /home/shaggy/.config/Mumble /home/shaggy/.config/qutebrowser"
INCLUDE4="/home/shaggy/.config/ranger /home/shaggy/.config/sxhkd /home/shaggy/.config/sxiv /home/shaggy/.config/wmfs"
INCLUDE5="/home/shaggy/.config/youtube-viewer /home/shaggy/.cortex /home/shaggy/.fonts /home/shaggy/.fluxbox"
INCLUDE5="/home/shaggy/.config/youtube-viewer /home/shaggy/.cortex /home/shaggy/.fluxbox"
INCLUDE6="/home/shaggy/.irssi /home/shaggy/.i3 /home/shaggy/.mpv /home/shaggy/.mutt /home/shaggy/.muttrc"
INCLUDE7="/home/shaggy/.nano /home/shaggy/.ncmpcpp /home/shaggy/.newsbeuter /home/shaggy/.offlineimap"
INCLUDE8="/home/shaggy/.ssh /home/shaggy/.themes /home/shaggy/.turses /home/shaggy/.password-store"
INCLUDE9="/home/shaggy/.vim /home/shaggy/.weechat /home/shaggy/scripts /home/shaggy/.aliasrc"
INCLUDE8="/home/shaggy/.ssh /home/shaggy/.turses /home/shaggy/.password-store"
INCLUDE9="/home/shaggy/.weechat /home/shaggy/scripts /home/shaggy/.aliasrc"
INCLUDE10="/home/shaggy/.cliweather /home/shaggy/.conkyrc /home/shaggy/.gitconfig /home/shaggy/.goobook_cache"
INCLUDE11="/home/shaggy/.msmtprc /home/shaggy/.nanorc /home/shaggy/.netrc /home/shaggy/.offlineimaprc"
INCLUDE12="/home/shaggy/.notmuch-config /home/shaggy/.Xdefaults /home/shaggy/.xinitrc /home/shaggy/.xprofile"

+ 16
- 0
rubyimg.rb View File

@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# Text File
# AUTHOR: shaggy
# FILE: rubyimg.rb
# ROLE: TODO (some explanation)
# CREATED: 2015-06-29 19:35:05
# MODIFIED: 2015-06-29 19:35:09
require "tco"
require "rmagick"

img = Magick::Image::read(ARGV[0]).first
img.each_pixel do |pixel, col, row|
c = [pixel.red, pixel.green, pixel.blue].map { |v| 256 * (v / 65535.0) }
pixel.opacity == 65535 ? print(" ") : print(" ".bg c)
puts if col >= img.columns - 1
end

+ 89
- 0
src/dunstify/Makefile View File

@@ -0,0 +1,89 @@
# dunst - Notification-daemon
# See LICENSE file for copyright and license details.

include config.mk

SRC = x.c \
dunst.c \
dbus.c \
utils.c \
option_parser.c \
settings.c \
rules.c \
menu.c \
notification.c
OBJ = ${SRC:.c=.o}

V ?= 0
ifeq (${V}, 0)
.SILENT:
endif

all: doc options dunst service

options:
@echo dunst build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"

.c.o:
@echo CC -c $<
${CC} -c $< ${CFLAGS}

${OBJ}: config.h config.mk

config.h: config.def.h
@if test -s $@; then echo $< is newer than $@, merge and save $@. If you haven\'t edited $@ you can just delete it && exit 1; fi
@echo creating $@ from $<
@cp $< $@

dunst: ${OBJ}
@echo "${CC} ${CFLAGS} -o $@ ${OBJ} ${LDFLAGS}"
@${CC} ${CFLAGS} -o $@ ${OBJ} ${LDFLAGS}

dunstify:
@${CC} -o $@ dunstify.c -std=c99 $(shell pkg-config --libs --cflags glib-2.0 libnotify)

debug: ${OBJ}
@echo CC -o $@
@${CC} ${CFLAGS} -O0 -o dunst ${OBJ} ${LDFLAGS}

clean:
@echo cleaning
rm -f ${OBJ}
rm -f dunst
rm -f dunst.1
rm -f org.knopwob.dunst.service
rm -f core
rm -f dunstify

doc: dunst.1
dunst.1: README.pod
pod2man --name=dunst -c "Dunst Reference" --section=1 --release=${VERSION} $< > $@

service:
@sed "s|##PREFIX##|$(PREFIX)|" org.knopwob.dunst.service.in > org.knopwob.dunst.service

install: all
@echo installing executables to ${DESTDIR}${PREFIX}/bin
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f dunst ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/dunst
@echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
mkdir -p ${DESTDIR}${MANPREFIX}/man1
cp -f dunst.1 ${DESTDIR}${MANPREFIX}/man1/
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dunst.1
mkdir -p "${DESTDIR}${PREFIX}/share/dunst"
cp -f dunstrc ${DESTDIR}${PREFIX}/share/dunst
mkdir -p "${DESTDIR}${PREFIX}/share/dbus-1/services/"
cp -vf org.knopwob.dunst.service "${DESTDIR}${PREFIX}/share/dbus-1/services/org.knopwob.dunst.service"

uninstall:
@echo removing executables from ${DESTDIR}${PREFIX}/bin
rm -f ${DESTDIR}${PREFIX}/bin/dunst
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
rm -f ${DESTDIR}${MANPREFIX}/man1/dunst
rm -f ${DESTDIR}${PREFIX}/share/dbus-1/service/org.knopwob.dunst.service

.PHONY: all options clean dist install uninstall

+ 0
- 0
src/dunstify/config.mk View File


BIN
src/dunstify/dunstify View File


+ 314
- 0
src/dunstify/dunstify.c View File

@@ -0,0 +1,314 @@
#include <glib.h>
#include <libnotify/notify.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

static gchar *appname = "dunstify";
static gchar *summary = NULL;
static gchar *body = NULL;
static NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL;
static gchar *urgency_str = NULL;
static gchar **hint_strs = NULL;
static gchar **action_strs = NULL;
static gint timeout = NOTIFY_EXPIRES_DEFAULT;
static gchar *icon = NULL;
static gboolean capabilities = false;
static gboolean serverinfo = false;
static gboolean printid = false;
static guint32 replace_id = 0;
static guint32 close_id = 0;
static gboolean block = false;

static GOptionEntry entries[] =
{
{ "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, "Name of your application", "NAME" },
{ "urgency", 'u', 0, G_OPTION_ARG_STRING, &urgency_str, "The urgency of this notification", "URG" },
{ "hints", 'h', 0, G_OPTION_ARG_STRING_ARRAY, &hint_strs, "User specified hints", "HINT" },
{ "action", 'A', 0, G_OPTION_ARG_STRING_ARRAY, &action_strs, "Actions the user can invoke", "ACTION" },
{ "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "The time until the notification expires", "TIMEOUT" },
{ "icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "An Icon that should be displayed with the notification", "ICON" },
{ "capabilities", 'c', 0, G_OPTION_ARG_NONE, &capabilities, "Print the server capabilities and exit", NULL},
{ "serverinfo", 's', 0, G_OPTION_ARG_NONE, &serverinfo, "Print server information and exit", NULL},
{ "printid", 'p', 0, G_OPTION_ARG_NONE, &printid, "Print id, which can be used to update/replace this notification", NULL},
{ "replace", 'r', 0, G_OPTION_ARG_INT, &replace_id, "Set id of this notification.", "ID"},
{ "close", 'C', 0, G_OPTION_ARG_INT, &close_id, "Set id of this notification.", "ID"},
{ "block", 'b', 0, G_OPTION_ARG_NONE, &block, "Block until notification is closed and print close reason", NULL},
{ NULL }
};

void die(int exit_value)
{
if (notify_is_initted())
notify_uninit();
exit(exit_value);
}

void print_capabilities(void)
{
GList *caps = notify_get_server_caps();
for (GList *iter = caps; iter; iter = iter->next) {
if (strlen(iter->data) > 0) {
g_print("%s\n", iter->data);
}
}
}

void print_serverinfo(void)
{
char *name;
char *vendor;
char *version;
char *spec_version;

if (!notify_get_server_info(&name, &vendor, &version, &spec_version)) {
g_printerr("Unable to get server information");
exit(1);
}

g_print("name:%s\nvendor:%s\nversion:%s\nspec_version:%s\n", name,
vendor,
version,
spec_version);
}

void parse_commandline(int argc, char *argv[])
{
GError *error = NULL;
GOptionContext *context;

context = g_option_context_new("- Dunstify");
g_option_context_add_main_entries(context, entries, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)){
g_printerr("Invalid commandline: %s\n", error->message);
exit(1);
}

g_option_context_free(context);

if (capabilities) {
print_capabilities();
die(0);
}

if (serverinfo) {
print_serverinfo();
die(0);
}

if (argc < 2 && close_id < 1) {
g_printerr("I need at least a summary\n");
die(1);
} else if (argc < 2) {
summary = g_strdup("These are not the summaries you are looking for");
} else {
summary = g_strdup(argv[1]);
}

if (argc > 2) {
body = g_strdup(argv[2]);
}

if (urgency_str) {
switch (urgency_str[0]) {
case 'l':
case 'L':
case '0':
urgency = NOTIFY_URGENCY_LOW;
break;
case 'n':
case 'N':
case '1':
urgency = NOTIFY_URGENCY_NORMAL;
break;
case 'c':
case 'C':
case '2':
urgency = NOTIFY_URGENCY_CRITICAL;
break;
default:
g_printerr("Unknown urgency: %s\n", urgency_str);
g_printerr("Assuming normal urgency\n");
break;
}
}
}

typedef struct _NotifyNotificationPrivate
{
guint32 id;
char *app_name;
char *summary;
char *body;

/* NULL to use icon data. Anything else to have server lookup icon */
char *icon_name;

/*
* -1 = use server default
* 0 = never timeout
* > 0 = Number of milliseconds before we timeout
*/
gint timeout;

GSList *actions;
GHashTable *action_map;
GHashTable *hints;

gboolean has_nondefault_actions;
gboolean updates_pending;

gulong proxy_signal_handler;

gint closed_reason;
} knickers;

int get_id(NotifyNotification *n)
{
knickers *kn = n->priv;

/* I'm sorry for taking a peek */
return kn->id;
}

int put_id(NotifyNotification *n, guint32 id)
{
knickers *kn = n->priv;

/* And know I'm putting stuff into
* your knickers. I'm sorry.
* I'm so sorry.
* */

kn->id = id;
}

void actioned(NotifyNotification *n, char *a, gpointer foo)
{
notify_notification_close(n, NULL);
g_print("%s\n", a);
die(0);
}

void closed(NotifyNotification *n, gpointer foo)
{
g_print("%d\n", notify_notification_get_closed_reason(n));
die(0);
}

void add_action(NotifyNotification *n, char *str)
{
char *action = str;
char *label = strstr(str, ",");

if (!label || *(label+1) == '\0') {
g_printerr("Malformed action. Excpected \"action,label\", got \"%s\"", str);
return;
}

*label = '\0';
label++;

notify_notification_add_action(n, action, label, actioned, NULL, NULL);
}

void add_hint(NotifyNotification *n, char *str)
{
char *type = str;
char *name = strstr(str, ":");
if (!name || *(name+1) == '\0') {
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
return;
}
*name = '\0';
name++;
char *value = strstr(name, ":");
if (!value || *(value+1) == '\0') {
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
return;
}
*value = '\0';
value++;

if (strcmp(type, "int") == 0)
notify_notification_set_hint_int32(n, name, atoi(value));
else if (strcmp(type, "double") == 0)
notify_notification_set_hint_double(n, name, atof(value));
else if (strcmp(type, "string") == 0)
notify_notification_set_hint_string(n, name, value);
else if (strcmp(type, "byte") == 0) {
gint h_byte = g_ascii_strtoull(value, NULL, 10);
if (h_byte < 0 || h_byte > 0xFF)
g_printerr("Not a byte: \"%s\"", value);
else
notify_notification_set_hint_byte(n, name, (guchar) h_byte);
} else
g_printerr("Malformed hint. Expected a type of int, double, string or byte, got %s\n", type);

}

int main(int argc, char *argv[])
{
#if !GLIB_CHECK_VERSION(2,35,0)
g_type_init();
#endif
parse_commandline(argc, argv);

if (!notify_init(appname)) {
g_printerr("Unable to initialize libnotify\n");
die(1);
}

NotifyNotification *n;
n = notify_notification_new(summary, body, icon);
notify_notification_set_timeout(n, timeout);
notify_notification_set_urgency(n, urgency);

GError *err = NULL;

if (close_id > 0) {
put_id(n, close_id);
notify_notification_close(n, &err);
if (err) {
g_printerr("Unable to close notification: %s\n", err->message);
die(1);
}
die(0);
}

if (replace_id > 0) {
put_id(n, replace_id);
}

GMainLoop *l = NULL;

if (block || action_strs)
l = g_main_loop_new(NULL, false);
g_signal_connect(n, "closed", G_CALLBACK(closed), NULL);

if (action_strs)
for (int i = 0; action_strs[i]; i++) {
add_action(n, action_strs[i]);
}

if (hint_strs)
for (int i = 0; hint_strs[i]; i++) {
add_hint(n, hint_strs[i]);
}


notify_notification_show(n, &err);
if (err) {
g_printerr("Unable to send notification: %s\n", err->message);
die(1);
}

if (block || action_strs)
g_main_loop_run(l);

if (printid) {
g_print("%d\n", get_id(n));
}

die(0);
}

Loading…
Cancel
Save