2007-05-23 00:49:31 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2007-2008 Transmission authors and contributors
|
2007-05-23 00:49:31 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TR_CORE_H
|
|
|
|
#define TR_CORE_H
|
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-05-23 00:49:31 +00:00
|
|
|
#include <glib-object.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-torrent.h"
|
2007-05-23 19:26:29 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
#define TR_CORE_TYPE (tr_core_get_type())
|
|
|
|
#define TR_CORE(o) G_TYPE_CHECK_INSTANCE_CAST((o),TR_CORE_TYPE,TrCore)
|
|
|
|
#define TR_IS_CORE(o) G_TYPE_CHECK_INSTANCE_TYPE((o),TR_CORE_TYPE)
|
|
|
|
#define TR_CORE_CLASS(k) G_TYPE_CHECK_CLASS_CAST((k),TR_CORE_TYPE,TrCoreClass)
|
|
|
|
#define TR_IS_CORE_CLASS(k) G_TYPE_CHECK_CLASS_TYPE((k),TR_CORE_TYPE)
|
|
|
|
#define TR_CORE_GET_CLASS(o) G_TYPE_INSTANCE_GET_CLASS((o),TR_CORE_TYPE,TrCoreClass)
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2008-01-16 16:03:18 +00:00
|
|
|
struct core_stats
|
|
|
|
{
|
|
|
|
int downloadCount;
|
|
|
|
int seedingCount;
|
|
|
|
float clientDownloadSpeed;
|
|
|
|
float clientUploadSpeed;
|
|
|
|
};
|
|
|
|
|
2008-02-09 17:29:05 +00:00
|
|
|
typedef struct TrCore
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2008-02-09 17:29:05 +00:00
|
|
|
GObject parent;
|
|
|
|
struct TrCorePrivate * priv;
|
|
|
|
}
|
|
|
|
TrCore;
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2008-02-09 17:29:05 +00:00
|
|
|
typedef struct TrCoreClass
|
2007-05-23 00:49:31 +00:00
|
|
|
{
|
2008-02-09 17:29:05 +00:00
|
|
|
GObjectClass parent;
|
|
|
|
|
2007-05-23 17:59:35 +00:00
|
|
|
/* "error" signal:
|
|
|
|
void handler( TrCore *, enum tr_core_err, const char *, gpointer ) */
|
2008-02-09 17:29:05 +00:00
|
|
|
int errsig;
|
|
|
|
|
2008-03-06 20:55:07 +00:00
|
|
|
/* "destination-prompt" signal:
|
2008-02-13 03:00:21 +00:00
|
|
|
void handler( TrCore *, GList *, gpointer ctor, gpointer userData ) */
|
2008-02-09 17:29:05 +00:00
|
|
|
int promptsig;
|
|
|
|
|
2007-05-24 03:29:23 +00:00
|
|
|
/* "quit" signal:
|
|
|
|
void handler( TrCore *, gpointer ) */
|
2008-02-09 17:29:05 +00:00
|
|
|
int quitsig;
|
|
|
|
|
2007-05-24 13:55:57 +00:00
|
|
|
/* "prefs-changed" signal:
|
|
|
|
void handler( TrCore *, int, gpointer ) */
|
2008-02-09 17:29:05 +00:00
|
|
|
int prefsig;
|
|
|
|
}
|
|
|
|
TrCoreClass;
|
2007-05-23 17:59:35 +00:00
|
|
|
|
|
|
|
enum tr_core_err
|
|
|
|
{
|
|
|
|
TR_CORE_ERR_ADD_TORRENT, /* adding a torrent failed */
|
|
|
|
/* no more torrents to be added, used for grouping torrent add errors */
|
|
|
|
TR_CORE_ERR_NO_MORE_TORRENTS,
|
|
|
|
TR_CORE_ERR_SAVE_STATE /* error saving state */
|
2007-05-23 00:49:31 +00:00
|
|
|
};
|
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
GType tr_core_get_type( void );
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
TrCore * tr_core_new( void );
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2007-05-23 01:47:42 +00:00
|
|
|
/* Return the model used without incrementing the reference count */
|
2008-02-14 17:18:00 +00:00
|
|
|
GtkTreeModel * tr_core_model( TrCore * self );
|
2007-05-23 00:49:31 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
tr_handle * tr_core_handle( TrCore * self );
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
const struct core_stats* tr_core_get_stats( const TrCore * self );
|
2008-02-09 17:29:05 +00:00
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
/******
|
|
|
|
*******
|
|
|
|
******/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load saved state and return number of torrents added.
|
|
|
|
* May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
|
|
|
|
*/
|
|
|
|
int tr_core_load( TrCore * self, gboolean forcepaused );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a torrent.
|
|
|
|
* May trigger an "error" signal with TR_CORE_ERR_ADD_TORRENT
|
|
|
|
* Caller must free the ctor.
|
|
|
|
*/
|
|
|
|
void tr_core_add_ctor( TrCore * self, tr_ctor * ctor );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a list of torrents.
|
|
|
|
* May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT
|
|
|
|
*/
|
|
|
|
void tr_core_add_list( TrCore * self,
|
|
|
|
GList * torrentFiles,
|
|
|
|
tr_ctor * ctor );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a torrent.
|
|
|
|
*/
|
|
|
|
void tr_core_add_torrent( TrCore*, TrTorrent* );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies listeners that torrents have been added.
|
|
|
|
* This should be called after one or more tr_core_add*() calls.
|
|
|
|
*/
|
|
|
|
void tr_core_torrents_added( TrCore * self );
|
|
|
|
|
|
|
|
/******
|
|
|
|
*******
|
|
|
|
******/
|
2007-05-23 01:47:42 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter );
|
2007-05-23 02:45:28 +00:00
|
|
|
|
2008-02-19 03:57:03 +00:00
|
|
|
void tr_core_remove_torrent( TrCore * self, TrTorrent * gtor, int deleteFiles );
|
|
|
|
|
2007-05-23 06:25:15 +00:00
|
|
|
/* update the model with current torrent status */
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_update( TrCore * self );
|
2007-05-23 02:45:28 +00:00
|
|
|
|
2007-05-24 03:29:23 +00:00
|
|
|
/* emit the "quit" signal */
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_quit( TrCore * self );
|
2007-05-24 03:29:23 +00:00
|
|
|
|
2007-05-24 13:55:57 +00:00
|
|
|
/* Set a preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_set_pref( TrCore * self, const char * key, const char * val );
|
2007-05-24 13:55:57 +00:00
|
|
|
|
|
|
|
/* Set a boolean preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val );
|
2007-05-24 13:55:57 +00:00
|
|
|
|
|
|
|
/* Set an integer preference value, save the prefs file, and emit the
|
|
|
|
"prefs-changed" signal */
|
2008-02-14 17:18:00 +00:00
|
|
|
void tr_core_set_pref_int( TrCore * self, const char * key, int val );
|
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-05-24 13:55:57 +00:00
|
|
|
|
2007-05-23 00:49:31 +00:00
|
|
|
/* column names for the model used to store torrent information */
|
|
|
|
/* keep this in sync with the type array in tr_core_init() in tr_core.c */
|
2007-12-19 02:46:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MC_NAME,
|
|
|
|
MC_NAME_COLLATED,
|
|
|
|
MC_HASH,
|
|
|
|
MC_TORRENT,
|
|
|
|
MC_TORRENT_RAW,
|
2007-12-28 06:12:53 +00:00
|
|
|
MC_STATUS,
|
2007-12-19 02:46:30 +00:00
|
|
|
MC_ID,
|
|
|
|
MC_ROW_COUNT
|
2007-05-23 00:49:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|