#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''****************************************************************************
**
** Copyright (C) 2008 Jędrzej Nowak <me@pigmej.eu>
** 
** This file may be used under the terms of the GNU General Public License
** version 2 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************'''

#launcher do dodania na panel gnome, można przeciągać pliki na niego
#wymaga klienta textowego
#umożliwia tworzenie.
#instalacja
#sudo mv wklej_to_applet.py /usr/local/bin/wklej_to_applet
#sudo chmod +x /usr/local/bin/wklej_to_applet


import sys
from subprocess import Popen, PIPE, call

try:
    plik=sys.argv[1]
except IndexError:
    Popen("notify-send -t 5000 -u critical 'Wklej.to: Błąd' 'Wymagane jest podanie pliku'",shell=True)
    sys.exit(1)
else:
    out=Popen('wklej_to -c -i %s'%plik,shell=True,stdout = PIPE,stderr = PIPE)
    wy,err=out.communicate()
    if err:
        call("notify-send -t 5000 -u critical 'Wklej.to: Błąd' '%s'"%err,shell=True)
        sys.exit(1)
    else:
        call("notify-send -i ~/.wklej_to/icons/notify.png -t 5000 'Wykonano' 'Link: %s \n Link został skopiowany do schowka'"%wy,shell=True)
        sys.exit(0)
