-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatspi_document_interface.cc
60 lines (49 loc) · 1.5 KB
/
atspi_document_interface.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <acacia/atspi/atspi_document_interface.h>
#include <assert.h>
#include <iostream>
#include <stdexcept>
#include <string>
#include "../utils.h"
namespace acacia {
std::string AtspiDocumentInterface::toString() const {
if (isNull())
return "Not implemented";
return "Attributes=" + StringVectorToString(getDocumentAttributes()) +
" Locale=" + getLocale();
}
std::vector<std::string> AtspiDocumentInterface::getDocumentAttributes() const {
GError* error = nullptr;
GHashTable* attributes_hash =
atspi_document_get_document_attributes(interface_.get(), &error);
std::vector<std::string> attributes;
if (error) {
std::string err_msg = error->message;
g_error_free(error);
throw std::runtime_error(err_msg);
}
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init(&iter, attributes_hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
std::string attr_entry =
static_cast<char*>(key) + std::string(":") + static_cast<char*>(value);
attributes.push_back(attr_entry);
}
g_hash_table_destroy(attributes_hash);
return attributes;
}
std::string AtspiDocumentInterface::getLocale() const {
if (isNull())
std::string();
GError* error = nullptr;
char* locale = atspi_document_get_locale(interface_.get(), &error);
if (error) {
std::string err_msg = error->message;
g_error_free(error);
throw std::runtime_error(err_msg);
}
std::string result(locale);
g_free(locale);
return result;
}
} // namespace acacia