commands.c 3.99 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1 2 3
/* See LICENSE file for license and copyright information */

#include "commands.h"
4 5
#include "bookmarks.h"
#include "database.h"
Moritz Lipp's avatar
Moritz Lipp committed
6
#include "zathura.h"
7
#include "print.h"
8
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
9 10

bool
Moritz Lipp's avatar
Moritz Lipp committed
11
cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
12 13 14 15 16
{
  return true;
}

bool
Moritz Lipp's avatar
Moritz Lipp committed
17
cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
18
{
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  if (zathura->document == NULL) {
    girara_notify(session, GIRARA_ERROR, "No document opened.");
    return false;
  }

  const unsigned int argc = girara_list_size(argument_list);
  if (argc != 1) {
    girara_notify(session, GIRARA_ERROR, "Invalid number of arguments given.");
    return false;
  }

  const char* bookmark = girara_list_nth(argument_list, 0);
  if (zathura_bookmark_remove(zathura, bookmark)) {
    girara_notify(session, GIRARA_INFO, "Removed bookmark: %s", bookmark);
  } else {
    girara_notify(session, GIRARA_ERROR, "Failed to remove bookmark: %s", bookmark);
  }

Moritz Lipp's avatar
Moritz Lipp committed
40 41 42 43
  return true;
}

bool
Moritz Lipp's avatar
Moritz Lipp committed
44
cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
45 46 47 48 49
{
  return true;
}

bool
Moritz Lipp's avatar
Moritz Lipp committed
50
cmd_close(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
51
{
52 53 54
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
55 56 57 58
  if (zathura->document == NULL) {
    // nothing needs to be done
    return true;
  }
59 60

  document_close(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
61

Moritz Lipp's avatar
Moritz Lipp committed
62 63 64 65
  return true;
}

bool
Moritz Lipp's avatar
Moritz Lipp committed
66
cmd_info(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
67 68 69 70
{
  return true;
}

Sebastian Ramacher's avatar
Sebastian Ramacher committed
71 72 73 74 75 76
bool
cmd_help(girara_session_t* session, girara_list_t* argument_list)
{
  return true;
}

77 78 79
bool
cmd_open(girara_session_t* session, girara_list_t* argument_list)
{
Sebastian Ramacher's avatar
Sebastian Ramacher committed
80 81 82 83 84 85
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  const int argc = girara_list_size(argument_list);
  if (argc > 2) {
86
    girara_notify(session, GIRARA_ERROR, "Too many arguments.");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
87 88 89
    return false;
  }
  else if (argc >= 1) {
90 91 92 93
    if (zathura->document) {
      document_close(zathura);
    }

Sebastian Ramacher's avatar
Sebastian Ramacher committed
94 95 96
    document_open(zathura, girara_list_nth(argument_list, 0), (argc == 2) ? girara_list_nth(argument_list, 1) :  NULL);
  }
  else {
97
    girara_notify(session, GIRARA_ERROR, "No arguments given.");
Sebastian Ramacher's avatar
Sebastian Ramacher committed
98 99 100
    return false;
  }

101 102 103
  return true;
}

Moritz Lipp's avatar
Moritz Lipp committed
104
bool
Moritz Lipp's avatar
Moritz Lipp committed
105
cmd_print(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
106
{
107 108 109 110 111
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

	if (zathura->document == NULL) {
112
    girara_notify(session, GIRARA_ERROR, "No open document.");
113 114 115
		return false;
	}

Sebastian Ramacher's avatar
Sebastian Ramacher committed
116
	print((zathura_t*) session->global.data);
117

Moritz Lipp's avatar
Moritz Lipp committed
118 119 120 121
  return true;
}

bool
Moritz Lipp's avatar
Moritz Lipp committed
122
cmd_save(girara_session_t* session, girara_list_t* argument_list)
Moritz Lipp's avatar
Moritz Lipp committed
123
{
124 125 126 127 128
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

	if (zathura->document == NULL) {
129
		girara_notify(session, GIRARA_ERROR, "No open document.");
130 131 132 133 134 135 136
		return false;
	}

  if (girara_list_size(argument_list) == 1) {
    document_save(zathura, girara_list_nth(argument_list, 0), false);
  }
  else {
137
    girara_notify(session, GIRARA_ERROR, "Invalid number of arguments.");
138 139 140 141 142 143 144 145 146 147 148 149 150 151
    return false;
  }

  return true;
}

bool
cmd_savef(girara_session_t* session, girara_list_t* argument_list)
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

	if (zathura->document == NULL) {
152 153
		girara_notify(session, GIRARA_ERROR, "No open document.");
    return false;
154 155 156 157 158 159
	}

  if (girara_list_size(argument_list) == 1) {
    document_save(zathura, girara_list_nth(argument_list, 0), true);
  }
  else {
160
    girara_notify(session, GIRARA_ERROR, "Invalid number of arguments.");
161 162 163
    return false;
  }

Moritz Lipp's avatar
Moritz Lipp committed
164 165
  return true;
}