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
|
||||
* 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"
|
||||
|
@ -64,19 +65,21 @@ PurpleApp::MessageReceived(BMessage* msg)
|
|||
int32 index = msg->FindInt32("index", 0);
|
||||
ProtocolInfo* info = fProtocols.ItemAt(index);
|
||||
|
||||
const char* nameConst = info->name.String();
|
||||
const char* idConst = info->id.String();
|
||||
char name[512] = { '\0' };
|
||||
char id[512] = { '\0' };
|
||||
strncpy(name, nameConst, 512);
|
||||
strncpy(id, idConst, 512);
|
||||
BMessage protocolInfo = info->settingsTemplate;
|
||||
protocolInfo.AddString("name", info->name);
|
||||
protocolInfo.AddString("id", info->id);
|
||||
|
||||
send_data(thread_id, 0, name, sizeof(char) * 512);
|
||||
send_data(thread_id, 0, id, sizeof(char) * 512);
|
||||
// Send message to requester
|
||||
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;
|
||||
}
|
||||
default:
|
||||
BApplication::MessageReceived(msg);
|
||||
BApplication::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,23 +90,81 @@ PurpleApp::_GetProtocolsInfo()
|
|||
GList* listIter = purple_plugins_get_protocols();
|
||||
for (int i = 0; listIter; listIter = listIter->next) {
|
||||
PurplePlugin* plugin = (PurplePlugin*)listIter->data;
|
||||
PurplePluginInfo* info = (PurplePluginInfo*)plugin->info;
|
||||
if (info)
|
||||
_SaveProtocolInfo(info);
|
||||
if (plugin)
|
||||
_SaveProtocolInfo(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PurpleApp::_SaveProtocolInfo(PurplePluginInfo* info)
|
||||
PurpleApp::_SaveProtocolInfo(PurplePlugin* plugin)
|
||||
{
|
||||
ProtocolInfo* proto = new ProtocolInfo;
|
||||
proto->id = info->id;
|
||||
proto->name = info->name;
|
||||
proto->id = plugin->info->id;
|
||||
proto->name = plugin->info->name;
|
||||
|
||||
PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
|
||||
proto->settingsTemplate = _ParseProtoOptions(info);
|
||||
|
||||
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 =
|
||||
{
|
||||
g_timeout_add,
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
*
|
||||
* 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., 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
|
||||
|
@ -42,6 +43,7 @@ typedef struct _PurpleGLibIOClosure {
|
|||
typedef struct _ProtocolInfo {
|
||||
BString name;
|
||||
BString id;
|
||||
BMessage settingsTemplate;
|
||||
} ProtocolInfo;
|
||||
|
||||
|
||||
|
@ -55,8 +57,8 @@ public:
|
|||
|
||||
private:
|
||||
void _GetProtocolsInfo();
|
||||
void _SaveProtocolInfo(PurplePluginInfo* info);
|
||||
|
||||
void _SaveProtocolInfo(PurplePlugin* plugin);
|
||||
BMessage _ParseProtoOptions(PurplePluginProtocolInfo* info);
|
||||
|
||||
BObjectList<ProtocolInfo> fProtocols;
|
||||
};
|
||||
|
|
|
@ -27,14 +27,16 @@ enum purple_message {
|
|||
*/
|
||||
|
||||
/*! Request a count of protocols. →Server
|
||||
* Response is sent directly to the requesting thread,
|
||||
* use receive_data() to catch it.
|
||||
* Response is sent directly to the requesting thread
|
||||
* as a message's code, use receive_data() to catch it.
|
||||
* Requires: int64 thread_id */
|
||||
PURPLE_REQUEST_PROTOCOL_COUNT = 1,
|
||||
|
||||
/*! Request protocol metadata. →Server
|
||||
* Response is sent directly to the requesting thread,
|
||||
* use receive_data() to catch it.
|
||||
* Response is sent directly to the requesting thread
|
||||
* 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 */
|
||||
PURPLE_REQUEST_PROTOCOL_INFO = 2
|
||||
};
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
*
|
||||
* 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., 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"
|
||||
|
@ -41,12 +42,16 @@ protocol_at(int32 i)
|
|||
|
||||
thread_id sender;
|
||||
|
||||
char name[512] = { '\0' };
|
||||
char id[512] = { '\0' };
|
||||
receive_data(&sender, name, sizeof(char) * 512);
|
||||
receive_data(&sender, id, sizeof(char) * 512);
|
||||
int32 size = receive_data(&sender, NULL, 0);
|
||||
char buffer[size];
|
||||
receive_data(&sender, buffer, size);
|
||||
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),
|
||||
fFriendlySignature(name)
|
||||
fFriendlySignature(name),
|
||||
fSettingsTemplate(settings)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -167,7 +173,7 @@ PurpleProtocol::UpdateSettings(BMessage* msg)
|
|||
BMessage
|
||||
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
|
||||
* 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
|
||||
|
@ -40,7 +41,8 @@ status_t connect_thread(void* data);
|
|||
|
||||
class PurpleProtocol : public ChatProtocol {
|
||||
public:
|
||||
PurpleProtocol(char name[512], char id[512]);
|
||||
PurpleProtocol(BString name, BString id,
|
||||
BMessage settings);
|
||||
|
||||
// ChatProtocol inheritance
|
||||
virtual status_t Init(ChatProtocolMessengerInterface* interface);
|
||||
|
@ -81,6 +83,7 @@ private:
|
|||
|
||||
BString fSignature;
|
||||
BString fFriendlySignature;
|
||||
BMessage fSettingsTemplate;
|
||||
};
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue