#!/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.
**
****************************************************************************'''

#nautilus script
#wymaga klienta textowego
#instalacja
#mv wklej_to_nautilus.py ~/.gnome2/nautilus-scripts/Wklej.to
#chmod +x ~/.gnome2/nautilus-scripts/Wklej.to

import os,sys
from subprocess import Popen, PIPE, call


plik=os.environ.get("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS")
if not plik:
    call("notify-send -t 5000 -u critical 'Wklej.to: Błąd' 'Wymagane jest podanie pliku'",shell=True)
    sys.exit(0)
else:
    plik=plik.strip()
    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)
