Skip to content

Commit 0479843

Browse files
authored
Merge pull request #12 from Agalin/structure_code
Structure code
2 parents f7271c8 + f337eea commit 0479843

File tree

28 files changed

+603
-318
lines changed

28 files changed

+603
-318
lines changed

Pidgin MacOS Integration.xcodeproj/xcuserdata/agalin.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 0 additions & 14 deletions
This file was deleted.

Pidgin MacOS Integration-Bridging-Header.h renamed to PidginMacOSIntegration-Bridging-Header.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@
2525
#import <version.h>
2626

2727
// Bridge fileś
28-
#import "plugin_load.h"
28+
#import "PluginLoad.h"
29+
#import "Callback.h"
30+
#import "Log.h"
31+
#import "Menu.h"
32+
#import "GtkTree.h"
33+
#import "GtkWindow.h"
34+
#import "PidginImage.h"

Pidgin MacOS Integration.xcodeproj/project.pbxproj renamed to PidginMacOSIntegration.xcodeproj/project.pbxproj

Lines changed: 129 additions & 37 deletions
Large diffs are not rendered by default.

Pidgin MacOS Integration.xcodeproj/project.xcworkspace/contents.xcworkspacedata renamed to PidginMacOSIntegration.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
//
2-
// plugin_load.h
3-
// Pidgin MacOS Integration
2+
// Callback.h
3+
// PidginMacOSIntegration
44
//
5-
// Created by Agalin on 16.08.2018.
6-
// Copyright © 2018 Agalin. All rights reserved.
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
77
//
88

9-
#ifndef plugin_load_h
10-
#define plugin_load_h
9+
#ifndef Callback_h
10+
#define Callback_h
1111

1212
#include <gtk/gtk.h>
13-
#include <glib.h>
1413
#include <plugin.h>
1514
#include <account.h>
1615

@@ -21,20 +20,6 @@ void register_conversation_created_callback(PurplePlugin *plugin, gboolean (*fun
2120
void register_buddy_list_created_callback(PurplePlugin *plugin, gboolean (*function)(PurpleBuddyList *, void *), const char* callback, void *data);
2221
void register_switch_page_callback(GtkWidget *notebook, const char* callback, GtkWidget *window, gboolean function (GtkWidget *notebook, GtkNotebookPage *notebook_page, int page, GtkWidget *data));
2322
void register_configuration_event_callback(GtkWidget *window, gboolean function (GtkWidget *widget, GdkEvent *event, gpointer user_data));
24-
void set_menu(GtkWidget *menu);
25-
GtkWindow* to_window(void* obj);
23+
void log_callback(const char* category, const char* message, const char* callback);
2624

27-
void log_all(const char* category, const char* message);
28-
void log_critical(const char* category, const char* message);
29-
30-
void plugin_load_oc(PurplePlugin *plugin);
31-
void plugin_init_oc(PurplePlugin *plugin);
32-
33-
void (*conv_test(void))(void);
34-
char* get_list_value_string(GtkTreeModel* model, GtkTreeIter* iter, gint column);
35-
36-
struct im_image_data {
37-
int id;
38-
GtkTextMark *mark;
39-
};
40-
#endif /* plugin_load_h */
25+
#endif /* Callback_h */
Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
//
2-
// test.m
3-
// Pidgin MacOS Integration
2+
// Callback.m
3+
// PidginMacOSIntegration
44
//
5-
// Created by Agalin on 11.08.2018.
6-
// Copyright © 2018 Agalin. All rights reserved.
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
77
//
88

9-
#import "plugin_load.h"
109
#import <Foundation/Foundation.h>
11-
#import "Pidgin_MacOS_Integration-Swift.h"
10+
#import "Callback.h"
11+
#import "Log.h"
12+
#import "pidgin/gtkblist.h"
1213

13-
void log_callback(const char* category, const char* message, const char* callback);
14-
15-
static Plugin* instance;
16-
17-
GtkWidget* get_config_frame(PurplePlugin* plugin) {
18-
return [Plugin getConfigFrame:plugin];
19-
}
20-
21-
PidginPluginUiInfo ui_info = {
22-
get_config_frame,
23-
0,
24-
25-
/* padding */
26-
NULL,
27-
NULL,
28-
NULL,
29-
NULL
30-
};
31-
32-
void plugin_load_oc(PurplePlugin *plugin) {
33-
log_critical("macos", "Load\n");
34-
instance = [[Plugin alloc]init];
35-
[instance pluginLoadWithPlugin:plugin];
36-
}
37-
38-
void plugin_init_oc(PurplePlugin *plugin) {
39-
log_critical("macos", "Init\n");
40-
// bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
41-
}
4214

4315
void register_callback_with_data(PurplePlugin *plugin, gboolean (*function)(PurpleAccount *, char **, char **, PurpleConversation *, PurpleMessageFlags *, void*), const char* callback, void* data) {
4416
log_callback("macos", "Registering callback %s for conversation...\n", callback);
@@ -89,35 +61,3 @@ void register_configuration_event_callback(GtkWidget *window, gboolean function
8961
log_all("macos", "Failure.");
9062
}
9163
}
92-
93-
void log_callback(const char* category, const char* message, const char* callback) {
94-
purple_debug_info(category, message, callback);
95-
}
96-
97-
void log_all(const char* category, const char* message)
98-
{
99-
purple_debug_info(category, "%s\n", message);
100-
}
101-
102-
void log_critical(const char* category, const char* message)
103-
{
104-
purple_debug(PURPLE_DEBUG_FATAL, category, "%s\n", message);
105-
}
106-
107-
void set_menu(GtkWidget *menu){
108-
gtkosx_application_set_menu_bar(gtkosx_application_get(), GTK_MENU_SHELL(menu));
109-
}
110-
111-
char* get_list_value_string(GtkTreeModel* model, GtkTreeIter* iter, gint column) {
112-
gchar* value = NULL;
113-
gtk_tree_model_get_value(model, iter, column, value);
114-
g_free(value);
115-
gtk_tree_model_get(model, iter, 0, value, -1);
116-
return value;
117-
}
118-
119-
GtkWindow* to_window(void* obj) {
120-
return GTK_WINDOW(obj);
121-
}
122-
123-
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// GtkTree.swift
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Cocoa
11+
12+
func selectNotificationSound (selection : UnsafeMutablePointer<GtkTreeSelection>!, model : GtkTreeModel!, path : GtkTreePath!, path_currently_selected : gboolean, userdata : gpointer!) -> gboolean {
13+
var iter = GtkTreeIter(stamp: 0, user_data: nil, user_data2: nil, user_data3: nil)
14+
let result = gtk_tree_model_get_iter(model, &iter, path)
15+
if (result == 1)
16+
{
17+
let index = Int(String(cString: gtk_tree_model_get_string_from_iter(model, &iter)))
18+
if let i = index {
19+
let n = Plugin.notificationSounds[i]
20+
// gtk_tree_model_get_value(model, &iter, 0, name)
21+
// gtk_tree_model_get(model, &iter, "Sound", name, -1)
22+
if (path_currently_selected == FALSE)
23+
{
24+
log_all("macos", "\(n) is going to be selected.")
25+
// let file = n.1.isEmpty ? n.0 : "\(n.1)/\(n.0)"
26+
let file = n.0
27+
purple_prefs_set_string(Plugin.Preferences.NotificationSound.path, file)
28+
NSSound(named: file)?.play()
29+
}
30+
else
31+
{
32+
log_all("macos", "\(n) is going to be unselected.")
33+
}
34+
}
35+
}
36+
else {
37+
log_critical("macos", "Selected nonexistent sound!")
38+
}
39+
return 1
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// GlibEnum.swift
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
enum GTypes : UInt {
12+
case G_TYPE_INVALID = 0b0 // 0 << 2
13+
case G_TYPE_NONE = 0b100 // 1 << 2
14+
case G_TYPE_INTERFACE = 0b1000 // 2 << 2
15+
case G_TYPE_CHAR = 0b1100 // 3 << 2
16+
case G_TYPE_UCHAR = 0b10000 // 4 << 2
17+
case G_TYPE_BOOLEAN = 0b10100 // 5 << 2
18+
case G_TYPE_INT = 0b11000 // 6 << 2
19+
case G_TYPE_UINT = 0b11100 // 7 << 2
20+
case G_TYPE_LONG = 0b100000 // 8 << 2
21+
case G_TYPE_ULONG = 0b100100 // 9 << 2
22+
case G_TYPE_INT64 = 0b101000 // 10 << 2
23+
case G_TYPE_UINT64 = 0b101100 // 11 << 2
24+
case G_TYPE_ENUM = 0b110000 // 12 << 2
25+
case G_TYPE_FLAGS = 0b110100 // 13 << 2
26+
case G_TYPE_FLOAT = 0b111000 // 14 << 2
27+
case G_TYPE_DOUBLE = 0b111100 // 15 << 2
28+
case G_TYPE_STRING = 0b1000000 // 16 << 2
29+
case G_TYPE_POINTER = 0b1000100 // 17 << 2
30+
case G_TYPE_BOXED = 0b1001000 // 18 << 2
31+
case G_TYPE_PARAM = 0b1001100 // 19 << 2
32+
case G_TYPE_OBJECT = 0b1010000 // 20 << 2
33+
case G_TYPE_VARIANT = 0b1010100 // 21 << 2
34+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// GlibGList.swift
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
func forEachInList(_ list: UnsafeMutablePointer<GList>?, function: (UnsafeMutablePointer<GList>) -> ()) {
12+
var element = list
13+
while(element != nil) {
14+
function(element!)
15+
element = element!.pointee.next
16+
}
17+
}

PidginMacOSItegration/Gtk/GtkTree.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// GtkTree.h
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#ifndef GtkTree_h
10+
#define GtkTree_h
11+
12+
#include <gtk/gtk.h>
13+
14+
char* get_list_value_string(GtkTreeModel* model, GtkTreeIter* iter, gint column);
15+
16+
#endif /* GtkTree_h */

PidginMacOSItegration/Gtk/GtkTree.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// GtkTree.m
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "GtkTree.h"
11+
12+
char* get_list_value_string(GtkTreeModel* model, GtkTreeIter* iter, gint column) {
13+
gchar* value = NULL;
14+
gtk_tree_model_get_value(model, iter, column, value);
15+
g_free(value);
16+
gtk_tree_model_get(model, iter, 0, value, -1);
17+
return value;
18+
}

PidginMacOSItegration/Gtk/GtkWindow.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// GtkWindow.h
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#ifndef GtkWindow_h
10+
#define GtkWindow_h
11+
12+
#include <gtk/gtk.h>
13+
14+
GtkWindow* to_window(void* obj);
15+
16+
#endif /* GtkWindow_h */

PidginMacOSItegration/Gtk/GtkWindow.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// GtkWindow.m
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "GtkWindow.h"
11+
12+
GtkWindow* to_window(void* obj) {
13+
return GTK_WINDOW(obj);
14+
}

PidginMacOSItegration/Log.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Log.h
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#ifndef Log_h
10+
#define Log_h
11+
12+
void log_all(const char* category, const char* message);
13+
void log_critical(const char* category, const char* message);
14+
void log_callback(const char* category, const char* message, const char* callback);
15+
16+
#endif /* Log_h */

PidginMacOSItegration/Log.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Log.m
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <debug.h>
11+
#import "Log.h"
12+
13+
void log_all(const char* category, const char* message)
14+
{
15+
purple_debug_info(category, "%s\n", message);
16+
}
17+
18+
void log_critical(const char* category, const char* message)
19+
{
20+
purple_debug(PURPLE_DEBUG_FATAL, category, "%s\n", message);
21+
}
22+
23+
void log_callback(const char* category, const char* message, const char* callback) {
24+
purple_debug_info(category, message, callback);
25+
}

PidginMacOSItegration/Log.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Log.swift
3+
// PidginMacOSIntegration
4+
//
5+
// Created by Agalin on 27/07/2020.
6+
// Copyright © 2020 Agalin. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
func debug(_ message: String) {
12+
#if DEBUG
13+
fputs(message, __stderrp)
14+
if(message.last != "\n")
15+
{
16+
fputs("\n", __stderrp)
17+
}
18+
log_all("macos", message)
19+
#endif
20+
}

0 commit comments

Comments
 (0)