~indicator-applet-developers/indicator-power/trunk.16.04

« back to all changes in this revision

Viewing changes to src/service.c

  • Committer: CI Train Bot
  • Author(s): Charles Kerr, charles kerr
  • Date: 2016-01-05 14:37:48 UTC
  • mfrom: (290.1.24 lp-1470767-low-battery-sound)
  • Revision ID: ci-train-bot@canonical.com-20160105143748-8vkmb6yhgz603fus
Play a 'low battery' sound when the low battery notification is shown.
 Fixes: #1470767
Approved by: Ted Gould, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
3
 
 *
4
 
 * Authors:
5
 
 *   Charles Kerr <charles.kerr@canonical.com>
6
 
 *   Ted Gould <ted@canonical.com>
 
2
 * Copyright 2013-2016 Canonical Ltd.
7
3
 *
8
4
 * This program is free software: you can redistribute it and/or modify it
9
5
 * under the terms of the GNU General Public License version 3, as published
16
12
 *
17
13
 * You should have received a copy of the GNU General Public License along
18
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *   Charles Kerr <charles.kerr@canonical.com>
 
18
 *   Ted Gould <ted@canonical.com>
19
19
 */
20
20
 
21
21
#include <glib/gi18n.h>
53
53
  PROP_0,
54
54
  PROP_BUS,
55
55
  PROP_DEVICE_PROVIDER,
 
56
  PROP_NOTIFIER,
56
57
  LAST_PROP
57
58
};
58
59
 
952
953
  g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_BUS]);
953
954
 
954
955
  /* export the battery properties */
955
 
  indicator_power_notifier_set_bus (p->notifier, connection);
 
956
  if (p->notifier != NULL)
 
957
    indicator_power_notifier_set_bus (p->notifier, connection);
956
958
 
957
959
  /* export the actions */
958
960
  if ((id = g_dbus_connection_export_action_group (connection,
1094
1096
        g_value_set_object (value, p->device_provider);
1095
1097
        break;
1096
1098
 
 
1099
      case PROP_NOTIFIER:
 
1100
        g_value_set_object (value, p->notifier);
 
1101
        break;
 
1102
 
1097
1103
      default:
1098
1104
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
1099
1105
    }
1113
1119
        indicator_power_service_set_device_provider (self, g_value_get_object (value));
1114
1120
        break;
1115
1121
 
 
1122
      case PROP_NOTIFIER:
 
1123
        indicator_power_service_set_notifier (self, g_value_get_object (value));
 
1124
        break;
 
1125
 
1116
1126
      default:
1117
1127
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
1118
1128
    }
1155
1165
  g_clear_object (&p->conn);
1156
1166
 
1157
1167
  indicator_power_service_set_device_provider (self, NULL);
 
1168
  indicator_power_service_set_notifier (self, NULL);
1158
1169
 
1159
1170
  G_OBJECT_CLASS (indicator_power_service_parent_class)->dispose (o);
1160
1171
}
1178
1189
 
1179
1190
  p->settings = g_settings_new ("com.canonical.indicator.power");
1180
1191
 
1181
 
  p->notifier = indicator_power_notifier_new ();
1182
 
 
1183
1192
  p->brightness = indicator_power_brightness_new();
1184
1193
  g_signal_connect_swapped(p->brightness, "notify::percentage",
1185
1194
                           G_CALLBACK(update_brightness_action_state), self);
1241
1250
    G_TYPE_OBJECT,
1242
1251
    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1243
1252
 
 
1253
  properties[PROP_NOTIFIER] = g_param_spec_object (
 
1254
    "notifier",
 
1255
    "Notifier",
 
1256
    "Notifies user of important battery changes",
 
1257
    G_TYPE_OBJECT,
 
1258
    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
1259
 
1244
1260
  g_object_class_install_properties (object_class, LAST_PROP, properties);
1245
1261
}
1246
1262
 
1249
1265
***/
1250
1266
 
1251
1267
IndicatorPowerService *
1252
 
indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider)
 
1268
indicator_power_service_new (IndicatorPowerDeviceProvider * device_provider,
 
1269
                             IndicatorPowerNotifier * notifier)
1253
1270
{
1254
1271
  GObject * o = g_object_new (INDICATOR_TYPE_POWER_SERVICE,
1255
1272
                              "device-provider", device_provider,
 
1273
                              "notifier", notifier,
1256
1274
                              NULL);
1257
1275
 
1258
1276
  return INDICATOR_POWER_SERVICE (o);
1291
1309
    }
1292
1310
}
1293
1311
 
 
1312
void
 
1313
indicator_power_service_set_notifier (IndicatorPowerService  * self,
 
1314
                                      IndicatorPowerNotifier * notifier)
 
1315
{
 
1316
  priv_t * p;
 
1317
 
 
1318
  g_return_if_fail (INDICATOR_IS_POWER_SERVICE (self));
 
1319
  g_return_if_fail (!notifier || INDICATOR_IS_POWER_NOTIFIER (notifier));
 
1320
  p = self->priv;
 
1321
 
 
1322
  if (p->notifier == notifier)
 
1323
    return;
 
1324
 
 
1325
  g_clear_object (&p->notifier);
 
1326
 
 
1327
  if (notifier != NULL)
 
1328
    {
 
1329
      p->notifier = g_object_ref (notifier);
 
1330
      indicator_power_notifier_set_bus (p->notifier, p->conn);
 
1331
    }
 
1332
}
 
1333
 
 
1334
 
1294
1335
/* If a device has multiple batteries and uses only one of them at a time,
1295
1336
   they should be presented as separate items inside the battery menu,
1296
1337
   but everywhere else they should be aggregated (bug 880881).