- if (!m.isRegistered()) {
- System.err.println("User is not registered.");
- System.exit(1);
- }
-
- try {
- m.sendQuitGroupMessage(decodeGroupId(ns.getString("group")));
- } catch (IOException e) {
- handleIOException(e);
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- } catch (AssertionError e) {
- handleAssertionError(e);
- } catch (GroupNotFoundException e) {
- handleGroupNotFoundException(e);
- }
-
- break;
- case "updateGroup":
- if (dBusConn != null) {
- System.err.println("updateGroup is not yet implementd via dbus");
- System.exit(1);
- }
- if (!m.isRegistered()) {
- System.err.println("User is not registered.");
- System.exit(1);
- }
-
- try {
- byte[] groupId = null;
- if (ns.getString("group") != null) {
- groupId = decodeGroupId(ns.getString("group"));
- }
- byte[] newGroupId = m.sendUpdateGroupMessage(groupId, ns.getString("name"), ns.<String>getList("member"), ns.getString("avatar"));
- if (groupId == null) {
- System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
- }
- } catch (IOException e) {
- handleIOException(e);
- } catch (AttachmentInvalidException e) {
- System.err.println("Failed to add avatar attachment for group\": " + e.getMessage());
- System.err.println("Aborting sending.");
- System.exit(1);
- } catch (GroupNotFoundException e) {
- handleGroupNotFoundException(e);
- } catch (EncapsulatedExceptions e) {
- handleEncapsulatedExceptions(e);
- }
-
- break;
- case "daemon":
- if (dBusConn != null) {
- System.err.println("Stop it.");
- System.exit(1);
- }
- if (!m.isRegistered()) {
- System.err.println("User is not registered.");
- System.exit(1);
- }
- DBusConnection conn = null;
- try {
- try {
- int busType;
- if (ns.getBoolean("system")) {
- busType = DBusConnection.SYSTEM;
- } else {
- busType = DBusConnection.SESSION;
- }
- conn = DBusConnection.getConnection(busType);
- conn.exportObject(SIGNAL_OBJECTPATH, m);
- conn.requestBusName(SIGNAL_BUSNAME);
- } catch (DBusException e) {
- e.printStackTrace();
- System.exit(3);
- }
- try {
- m.receiveMessages(3600, false, new DbusReceiveMessageHandler(m, conn));
- } catch (IOException e) {
- System.err.println("Error while receiving messages: " + e.getMessage());
- System.exit(3);
- } catch (AssertionError e) {
- handleAssertionError(e);
- }
- } finally {
- if (conn != null) {
- conn.disconnect();
- }