monotone

monotone Mtn Source Tree

Root/app_state.cc

1#include <termios.h>
2#include <iostream>
3
4#include "app_state.hh"
5#include "database.hh"
6#include "transforms.hh"
7#include "work.hh"
8
9// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
10// all rights reserved.
11// licensed to the public under the terms of the GNU GPL (>= 2)
12// see the file COPYING for details
13
14using namespace std;
15
16static string const database_option("database");
17static string const branch_option("branch");
18static string const key_option("key");
19
20app_state::app_state()
21 : branch_name(""), db(""), options_changed(false)
22{
23 options[database_option] = string("");
24 options[branch_option] = string("");
25 local_path o_path;
26 get_options_path(o_path);
27 if (file_exists(o_path))
28 {
29 data dat;
30 read_data(o_path, dat);
31 read_options_map(dat, options);
32
33 string dbname = absolutify(options[database_option]());
34 if (dbname != "")
35db.set_filename(dbname);
36 branch_name = options[branch_option];
37 internalize_rsa_keypair_id(options[key_option], signing_key);
38 }
39}
40
41app_state::~app_state()
42{
43}
44
45void app_state::set_database(utf8 const & filename)
46{
47 options[database_option] = utf8(absolutify(filename()));
48 db.set_filename(filename());
49 options_changed = true;
50}
51
52void app_state::set_branch(utf8 const & branch)
53{
54 options[branch_option] = branch;
55 branch_name = branch();
56 options_changed = true;
57}
58
59void app_state::set_signing_key(utf8 const & key)
60{
61 rsa_keypair_id k;
62 internalize_rsa_keypair_id(key, k);
63 options[key_option] = key;
64 signing_key = k;
65 options_changed = true;
66}
67
68void app_state::write_options()
69{
70 if (options_changed)
71 {
72 local_path o_path;
73 get_options_path(o_path);
74
75 data dat;
76 write_options_map(dat, options);
77 write_data(o_path, dat);
78 }
79}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status