]> git.lyx.org Git - features.git/blob - src/frontends/kde/FormVCLog.C
802e1a5791eea31b3f426e16376ca02d5dea8552
[features.git] / src / frontends / kde / FormVCLog.C
1 /**
2  * \file FormVCLog.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10 #include <fstream> 
11
12 #include "Dialogs.h"
13 #include "FormVCLog.h"
14 #include "gettext.h"
15 #include "buffer.h"
16 #include "support/lstrings.h"
17 #include "LyXView.h"
18 #include "lyxfunc.h"
19 #include "logdlg.h"
20 #include "lyxvc.h"
21
22 using std::ifstream;
23 using std::getline;
24
25 FormVCLog::FormVCLog(LyXView *v, Dialogs *d)
26         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
27 {
28         d->showVCLogFile.connect(slot(this, &FormVCLog::show));
29 }
30
31
32 FormVCLog::~FormVCLog()
33 {
34         delete dialog_;
35 }
36
37
38 void FormVCLog::update()
39 {
40         supdate();
41 }
42
43  
44 void FormVCLog::supdate(bool)
45 {
46         const string logfile = lv_->view()->buffer()->lyxvc.getLogFile();
47
48         dialog_->setCaption(string(_("Version control log for ") + lv_->view()->buffer()->fileName()).c_str());
49
50         dialog_->setLogText("");
51
52         ifstream ifstr(logfile.c_str());
53         if (!ifstr) {
54                 dialog_->setLogText(_("No version control log file found"));
55                 lyx::unlink(logfile);
56                 return;
57         }
58
59         string text;
60         string line;
61
62         while (getline(ifstr, line))
63                 text += line + "\n";
64  
65         dialog_->setLogText(text);
66
67         lyx::unlink(logfile);
68 }
69
70
71 void FormVCLog::show()
72 {
73         if (!dialog_)
74                 dialog_ = new LogDialog(this, 0, _("LyX: Version Control Log"));
75
76         if (!dialog_->isVisible()) {
77                 h_ = d_->hideBufferDependent.connect(slot(this, &FormVCLog::hide));
78                 u_ = d_->updateBufferDependent.connect(slot(this, &FormVCLog::supdate));
79         }
80
81         dialog_->raise();
82         dialog_->setActiveWindow();
83
84         update();
85         dialog_->show();
86 }
87
88
89 void FormVCLog::close()
90 {
91         h_.disconnect();
92         u_.disconnect();
93 }
94
95
96 void FormVCLog::hide()
97 {
98         dialog_->hide();
99         close();
100 }