LimeWirePlugin.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.plugin.limewire |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* 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.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.plugin.limewire;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import javax.swing.*;
import org.apache.log4j.Logger;
import org.xnap.XNapFacade;
import org.xnap.gui.AbstractPreferencesDialog;
import org.xnap.gui.StatusBar;
import org.xnap.gui.XNapFrame;
import org.xnap.gui.event.AbstractPreferencesDialogListener;
import org.xnap.gui.util.IconHelper;
import org.xnap.plugin.AbstractPlugin;
import org.xnap.search.SearchManager;
import org.xnap.util.FileHelper;
import org.xnap.util.Preferences;
import com.limegroup.gnutella.RouterService;
import com.limegroup.gnutella.settings.ApplicationSettings;
import com.limegroup.gnutella.settings.ChatSettings;
import com.limegroup.gnutella.settings.ConnectionSettings;
import com.limegroup.gnutella.settings.DownloadSettings;
import com.limegroup.gnutella.settings.SecuritySettings;
import com.limegroup.gnutella.settings.SharingSettings;
import com.limegroup.gnutella.settings.UltrapeerSettings;
import com.limegroup.gnutella.settings.UploadSettings;
/**
* Provides a gnutella network plugin based on LimeWire.
*/
public class LimeWirePlugin extends AbstractPlugin
{
//--- Constant(s) ---
public static String ICON_FILENAME = "limewire.png";
public static Icon ICON_16 = IconHelper.getIcon(ICON_FILENAME, 16, false);
//--- Data Field(s) ---
private static Logger logger = Logger.getLogger(LimeWirePlugin.class);
private static Preferences prefs = Preferences.getInstance();
private static LimeWirePlugin singleton;
private LimeWirePreferences limewirePrefs;
private LimeWirePanel jpLimeWire;
private LimeWireStatusPanel statusPanel;
private PreferencesDialogListener pdl;
private LimeWireSearchManager searchManager;
private LimeWireServantManager servantManager;
private LimeWireChatManager chatManager;
private LimeWireTransferManager transferManager;
private boolean connectStarted = false;
//--- Constructor(s) ---
public LimeWirePlugin()
{
}
//--- Method(s) ---
public static LimeWirePlugin getInstance()
{
return singleton;
}
public static LimeWirePanel getConnectionPanel()
{
return singleton.jpLimeWire;
}
public static LimeWireChatManager getChatManager()
{
return singleton.chatManager;
}
public static LimeWirePreferences getPreferences()
{
return singleton.limewirePrefs;
}
public static LimeWireSearchManager getSearchManager()
{
return singleton.searchManager;
}
public static LimeWireServantManager getServantManager()
{
return singleton.servantManager;
}
public static LimeWireTransferManager getTransferManager()
{
return singleton.transferManager;
}
public void connect()
{
if (connectStarted) {
return;
}
connectStarted = true;
RouterService.connect();
if (jpLimeWire != null) {
Runnable runner = new Runnable()
{
public void run()
{
if (jpLimeWire != null) {
jpLimeWire.setConnected(true);
}
}
};
SwingUtilities.invokeLater(runner);
}
}
public void disconnect()
{
if (!connectStarted) {
return;
}
connectStarted = false;
RouterService.disconnect();
if (jpLimeWire != null) {
Runnable runner = new Runnable()
{
public void run()
{
if (jpLimeWire != null) {
jpLimeWire.setConnected(false);
}
}
};
SwingUtilities.invokeLater(runner);
}
}
/**
* Starts the plugin.
*/
public void start()
{
singleton = this;
limewirePrefs = new LimeWirePreferences();
initializeSettings();
servantManager = new LimeWireServantManager();
chatManager = new LimeWireChatManager();
transferManager = new LimeWireTransferManager();
searchManager = new LimeWireSearchManager();
SearchManager.getInstance().add(searchManager);
LimeWireCallback callback = new LimeWireCallback();
RouterService router = new RouterService(callback);
router.start();
}
/**
* Starts the GUI of the plugin.
*/
public void startGUI()
{
jpLimeWire = new LimeWirePanel();
jpLimeWire.setConnected(connectStarted);
XNapFrame.getInstance().insertTab
(getInfo().getName(), IconHelper.getListIcon(ICON_FILENAME),
jpLimeWire);
pdl = new PreferencesDialogListener();
XNapFacade.addPluginPreferencesDialogListener(pdl);
// add status panel
statusPanel = new LimeWireStatusPanel();
StatusBar.getInstance().addComponent(statusPanel);
if (limewirePrefs.getAutoConnect()) {
connect();
}
}
/**
*
*/
private void initializeSettings()
{
ApplicationSettings.COUNTRY.setValue(Locale.getDefault().getCountry());
ApplicationSettings.INSTALLED.setValue(false);
ApplicationSettings.LANGUAGE.setValue(Locale.getDefault().getLanguage());
ApplicationSettings.LOCALE_VARIANT.setValue(Locale.getDefault().getVariant());
ChatSettings.CHAT_ENABLED.setValue(limewirePrefs.getBoolean("chatEnabled"));
DownloadSettings.MAX_DOWNLOAD_BYTES_PER_SEC.setValue(prefs.getDownloadThrottle());
DownloadSettings.MAX_SIM_DOWNLOAD.setValue(prefs.getMaxDownloads());
SecuritySettings.COOKIES_FILE.setValue(FileHelper.getHomeDir() + "limewire_cookies");
SecuritySettings.ACCEPT_AUTHENTICATED_CONNECTIONS_ONLY.setValue(limewirePrefs.getAuthenticatedConnectionsOnly());
SharingSettings.ALLOW_BROWSER.setValue(limewirePrefs.getBoolean("allowBrowser"));
SharingSettings.CLEAR_DOWNLOAD.setValue(false);
SharingSettings.CLEAR_UPLOAD.setValue(false);
SharingSettings.FREELOADER_ALLOWED.setValue(prefs.getUseMinimumShares() ? 0 : 100);
SharingSettings.FREELOADER_FILES.setValue(prefs.getMinimumShares());
UploadSettings.SOFT_MAX_UPLOADS.setValue(prefs.getMaxUploads());
UploadSettings.HARD_MAX_UPLOADS.setValue(prefs.getMaxUploads());
UploadSettings.MAX_UPLOAD_BYTES_PER_SEC.setValue(prefs.getUploadThrottle());
UploadSettings.UPLOADS_PER_PERSON.setValue(prefs.getMaxUploadsPerUser());
ConnectionSettings.CONNECT_ON_STARTUP.setValue(limewirePrefs.getAutoConnect());
ConnectionSettings.CONNECTION_SPEED.setValue(prefs.getLinkSpeed());
ConnectionSettings.LOCAL_IS_PRIVATE.setValue(false);
ConnectionSettings.NUM_CONNECTIONS.setValue(5);
ConnectionSettings.FORCED_PORT.setValue(limewirePrefs.getInt("forcedPort"));
ConnectionSettings.PORT.setValue(limewirePrefs.getPort());
ConnectionSettings.FORCE_IP_ADDRESS.setValue(limewirePrefs.getBoolean("forceIPAdress"));
ConnectionSettings.FORCED_IP_ADDRESS_STRING.setValue(limewirePrefs.get("forcedIPAddressString"));
// FIX: s.setExtensions();
UltrapeerSettings.DISABLE_ULTRAPEER_MODE.setValue(limewirePrefs.getDisableUltraPeer());
updateDirectories();
}
/**
*
*/
private void updateDirectories()
{
String[] dirs = prefs.getUploadDirs();
File[] files = new File[dirs.length];
for (int i = 0; i < dirs.length; i++) {
files[i] = new File(dirs[i]);
}
SharingSettings.DIRECTORIES_TO_SHARE.setValue(files);
// the SettingsManager tries to create a subdirectory
// "Incompletes" at the parent directory, so we start
// one level below
try {
SharingSettings.setSaveDirectory(new File(prefs.getIncompleteDir() + ".gnutella"));
}
catch (IOException e) {
logger.warn("Could not set download directory", e);
}
SharingSettings.DIRECTORY_FOR_SAVING_FILES.setValue(new File(prefs.getDownloadDir()));
}
/**
* Stops the plugin. Disposes all singletons.
*/
public void stop()
{
disconnect();
limewirePrefs = null;
}
/**
* Stops the GUI of the plugin.
*/
public void stopGUI()
{
pdl.dispose();
XNapFacade.removePluginPreferencesDialogListener(pdl);
pdl = null;
SearchManager.getInstance().remove(searchManager);
chatManager.removeAll();
transferManager.removeAll();
// stop update timer
jpLimeWire.setConnected(false);
// shutdown
RouterService.shutdown();
// remove status panel
StatusBar.getInstance().removeComponent(statusPanel);
// dispose gui
XNapFrame.getInstance().removeTab(jpLimeWire);
jpLimeWire = null;
}
public static void updateStatusPanel()
{
if (singleton.statusPanel != null) {
singleton.statusPanel.updateStatus();
}
}
// --- Inner Class(es) ---
private class PreferencesDialogListener
extends AbstractPreferencesDialogListener
{
public void addPanels(AbstractPreferencesDialog dialog, List panels)
{
LimeWirePreferencesPanel jpp = new LimeWirePreferencesPanel();
panels.add(jpp);
panels.add(dialog.addPanel(jpp, ICON_FILENAME));
}
}
}
The table below shows all metrics for LimeWirePlugin.java.




