/*
* AddDialogHandler.java
*
* Copyright (C) 2008 Gimme
*
* 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 of the License, 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, see <http://www.gnu.org/licenses/>.
*/
package net.sf.gimme;
import net.sf.gimme.event.GUIEventListener;
import net.sf.gimme.event.GUIEventPipe;
import java.net.MalformedURLException;
import java.net.URL;
import org.gnome.glade.XML;
import org.gnome.gtk.Button;
import org.gnome.gtk.Entry;
import org.gnome.gtk.Widget;
import org.gnome.gtk.Window;
/**
*
* @author aiden
*/
public class AddDialogHandler implements GUIEventListener
{
private XML glade;
private DownloadManager manager;
private final Window dialog;
public AddDialogHandler(XML glade, DownloadManager manager)
{
this.glade = glade;
this.manager = manager;
dialog = (Window)glade.getWidget("wnd_add");
dialog.showAll();
Button ok = (Button)glade.getWidget("btn_ok");
ok.connect(new GUIEventPipe(this, "ok"));
Button cancel = (Button)glade.getWidget("btn_cancel");
cancel.connect(new GUIEventPipe(this, "cancel"));
}
public void onClicked(Widget widget, String userData)
{
if(userData.equals("ok"))
{
Entry entry = (Entry)glade.getWidget("txt_url");
System.out.println(entry.getText());
try
{
manager.addDownload(new Download(new URL(entry.getText()), Configuration.get().getNumberOfSegments()));
dialog.hide();
}
catch(MalformedURLException ex)
{
ex.printStackTrace();
}
}
else if(userData.equals("cancel"))
{
dialog.hide();
}
}
}