Receive protocols' settings templates from libpurple
This commit is contained in:
parent
ddaf39c300
commit
6507a4182f
|
@ -14,7 +14,8 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PurpleApp.h"
|
#include "PurpleApp.h"
|
||||||
|
@ -64,19 +65,21 @@ PurpleApp::MessageReceived(BMessage* msg)
|
||||||
int32 index = msg->FindInt32("index", 0);
|
int32 index = msg->FindInt32("index", 0);
|
||||||
ProtocolInfo* info = fProtocols.ItemAt(index);
|
ProtocolInfo* info = fProtocols.ItemAt(index);
|
||||||
|
|
||||||
const char* nameConst = info->name.String();
|
BMessage protocolInfo = info->settingsTemplate;
|
||||||
const char* idConst = info->id.String();
|
protocolInfo.AddString("name", info->name);
|
||||||
char name[512] = { '\0' };
|
protocolInfo.AddString("id", info->id);
|
||||||
char id[512] = { '\0' };
|
|
||||||
strncpy(name, nameConst, 512);
|
|
||||||
strncpy(id, idConst, 512);
|
|
||||||
|
|
||||||
send_data(thread_id, 0, name, sizeof(char) * 512);
|
// Send message to requester
|
||||||
send_data(thread_id, 0, id, sizeof(char) * 512);
|
ssize_t size = protocolInfo.FlattenedSize();
|
||||||
|
char buffer[size];
|
||||||
|
|
||||||
|
send_data(thread_id, size, NULL, 0);
|
||||||
|
protocolInfo.Flatten(buffer, size);
|
||||||
|
send_data(thread_id, 0, buffer, size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(msg);
|
BApplication::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,23 +90,81 @@ PurpleApp::_GetProtocolsInfo()
|
||||||
GList* listIter = purple_plugins_get_protocols();
|
GList* listIter = purple_plugins_get_protocols();
|
||||||
for (int i = 0; listIter; listIter = listIter->next) {
|
for (int i = 0; listIter; listIter = listIter->next) {
|
||||||
PurplePlugin* plugin = (PurplePlugin*)listIter->data;
|
PurplePlugin* plugin = (PurplePlugin*)listIter->data;
|
||||||
PurplePluginInfo* info = (PurplePluginInfo*)plugin->info;
|
if (plugin)
|
||||||
if (info)
|
_SaveProtocolInfo(plugin);
|
||||||
_SaveProtocolInfo(info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PurpleApp::_SaveProtocolInfo(PurplePluginInfo* info)
|
PurpleApp::_SaveProtocolInfo(PurplePlugin* plugin)
|
||||||
{
|
{
|
||||||
ProtocolInfo* proto = new ProtocolInfo;
|
ProtocolInfo* proto = new ProtocolInfo;
|
||||||
proto->id = info->id;
|
proto->id = plugin->info->id;
|
||||||
proto->name = info->name;
|
proto->name = plugin->info->name;
|
||||||
|
|
||||||
|
PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
|
||||||
|
proto->settingsTemplate = _ParseProtoOptions(info);
|
||||||
|
|
||||||
fProtocols.AddItem(proto);
|
fProtocols.AddItem(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BMessage
|
||||||
|
PurpleApp::_ParseProtoOptions(PurplePluginProtocolInfo* info)
|
||||||
|
{
|
||||||
|
BMessage temp;
|
||||||
|
|
||||||
|
GList* prefIter = info->protocol_options;
|
||||||
|
for (int i = 0; prefIter != NULL; prefIter = prefIter->next)
|
||||||
|
{
|
||||||
|
PurpleAccountOption* pref = (PurpleAccountOption*)prefIter->data;
|
||||||
|
PurplePrefType type = pref->type;
|
||||||
|
int32 bType;
|
||||||
|
|
||||||
|
BMessage setting;
|
||||||
|
setting.AddString("name", pref->pref_name);
|
||||||
|
setting.AddString("description", pref->text);
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case PURPLE_PREF_BOOLEAN:
|
||||||
|
{
|
||||||
|
bType = B_BOOL_TYPE;
|
||||||
|
setting.AddBool("default", pref->default_value.boolean);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PURPLE_PREF_INT:
|
||||||
|
{
|
||||||
|
bType = B_INT32_TYPE;
|
||||||
|
setting.AddInt32("default", pref->default_value.integer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PURPLE_PREF_STRING_LIST: {
|
||||||
|
bType = B_STRING_TYPE;
|
||||||
|
BString implicit;
|
||||||
|
GList* lists;
|
||||||
|
for (int j = 0; lists != NULL; lists = lists->next)
|
||||||
|
implicit << " " << lists->data;
|
||||||
|
setting.AddString("default", implicit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
bType = B_STRING_TYPE;
|
||||||
|
setting.AddString("default", pref->default_value.string);
|
||||||
|
}
|
||||||
|
if (pref->masked)
|
||||||
|
setting.AddBool("is_hidden", true);
|
||||||
|
setting.AddString("error",
|
||||||
|
BString(pref->text).Append(" needs to be specified."));
|
||||||
|
setting.AddInt32("type", bType);
|
||||||
|
temp.AddMessage("setting", &setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PurpleEventLoopUiOps _glib_eventloops =
|
static PurpleEventLoopUiOps _glib_eventloops =
|
||||||
{
|
{
|
||||||
g_timeout_add,
|
g_timeout_add,
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PURPLE_APP_H
|
#ifndef _PURPLE_APP_H
|
||||||
|
@ -42,6 +43,7 @@ typedef struct _PurpleGLibIOClosure {
|
||||||
typedef struct _ProtocolInfo {
|
typedef struct _ProtocolInfo {
|
||||||
BString name;
|
BString name;
|
||||||
BString id;
|
BString id;
|
||||||
|
BMessage settingsTemplate;
|
||||||
} ProtocolInfo;
|
} ProtocolInfo;
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,8 +57,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _GetProtocolsInfo();
|
void _GetProtocolsInfo();
|
||||||
void _SaveProtocolInfo(PurplePluginInfo* info);
|
void _SaveProtocolInfo(PurplePlugin* plugin);
|
||||||
|
BMessage _ParseProtoOptions(PurplePluginProtocolInfo* info);
|
||||||
|
|
||||||
BObjectList<ProtocolInfo> fProtocols;
|
BObjectList<ProtocolInfo> fProtocols;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,14 +27,16 @@ enum purple_message {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*! Request a count of protocols. →Server
|
/*! Request a count of protocols. →Server
|
||||||
* Response is sent directly to the requesting thread,
|
* Response is sent directly to the requesting thread
|
||||||
* use receive_data() to catch it.
|
* as a message's code, use receive_data() to catch it.
|
||||||
* Requires: int64 thread_id */
|
* Requires: int64 thread_id */
|
||||||
PURPLE_REQUEST_PROTOCOL_COUNT = 1,
|
PURPLE_REQUEST_PROTOCOL_COUNT = 1,
|
||||||
|
|
||||||
/*! Request protocol metadata. →Server
|
/*! Request protocol metadata. →Server
|
||||||
* Response is sent directly to the requesting thread,
|
* Response is sent directly to the requesting thread
|
||||||
* use receive_data() to catch it.
|
* with two subsquent messages (using receive_data())―
|
||||||
|
* the first sending the size of the subsequently sent
|
||||||
|
* flattened BMessage.
|
||||||
* Requires: int32 protocol_index, int64 thread_id */
|
* Requires: int32 protocol_index, int64 thread_id */
|
||||||
PURPLE_REQUEST_PROTOCOL_INFO = 2
|
PURPLE_REQUEST_PROTOCOL_INFO = 2
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PurpleProtocol.h"
|
#include "PurpleProtocol.h"
|
||||||
|
@ -41,12 +42,16 @@ protocol_at(int32 i)
|
||||||
|
|
||||||
thread_id sender;
|
thread_id sender;
|
||||||
|
|
||||||
char name[512] = { '\0' };
|
int32 size = receive_data(&sender, NULL, 0);
|
||||||
char id[512] = { '\0' };
|
char buffer[size];
|
||||||
receive_data(&sender, name, sizeof(char) * 512);
|
receive_data(&sender, buffer, size);
|
||||||
receive_data(&sender, id, sizeof(char) * 512);
|
BMessage temp;
|
||||||
|
temp.Unflatten(buffer);
|
||||||
|
|
||||||
return (ChatProtocol*)new PurpleProtocol(name, id);
|
BString name = temp.FindString("name");
|
||||||
|
BString id = temp.FindString("id");
|
||||||
|
|
||||||
|
return (ChatProtocol*)new PurpleProtocol(name, id, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,10 +125,11 @@ connect_thread(void* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PurpleProtocol::PurpleProtocol(char name[512], char id[512])
|
PurpleProtocol::PurpleProtocol(BString name, BString id, BMessage settings)
|
||||||
:
|
:
|
||||||
fSignature(id),
|
fSignature(id),
|
||||||
fFriendlySignature(name)
|
fFriendlySignature(name),
|
||||||
|
fSettingsTemplate(settings)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +173,7 @@ PurpleProtocol::UpdateSettings(BMessage* msg)
|
||||||
BMessage
|
BMessage
|
||||||
PurpleProtocol::SettingsTemplate(const char* name)
|
PurpleProtocol::SettingsTemplate(const char* name)
|
||||||
{
|
{
|
||||||
return BMessage();
|
return fSettingsTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PURPLE_PROTOCOL_H
|
#ifndef _PURPLE_PROTOCOL_H
|
||||||
|
@ -40,7 +41,8 @@ status_t connect_thread(void* data);
|
||||||
|
|
||||||
class PurpleProtocol : public ChatProtocol {
|
class PurpleProtocol : public ChatProtocol {
|
||||||
public:
|
public:
|
||||||
PurpleProtocol(char name[512], char id[512]);
|
PurpleProtocol(BString name, BString id,
|
||||||
|
BMessage settings);
|
||||||
|
|
||||||
// ChatProtocol inheritance
|
// ChatProtocol inheritance
|
||||||
virtual status_t Init(ChatProtocolMessengerInterface* interface);
|
virtual status_t Init(ChatProtocolMessengerInterface* interface);
|
||||||
|
@ -81,6 +83,7 @@ private:
|
||||||
|
|
||||||
BString fSignature;
|
BString fSignature;
|
||||||
BString fFriendlySignature;
|
BString fFriendlySignature;
|
||||||
|
BMessage fSettingsTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue