TrackGit
CloneWindow.cpp
Go to the documentation of this file.
1 
7 #include "CloneWindow.h"
8 
9 #include <stdio.h>
10 
11 #include <AppKit.h>
12 #include <Catalog.h>
13 #include <LayoutBuilder.h>
14 #include <SupportKit.h>
15 
16 #define B_TRANSLATION_CONTEXT "TrackGit"
17 
18 
25 CloneWindow::CloneWindow(BString repo, BString dirPath, Clone* clone)
26  :
27  TrackGitWindow(repo, BRect(0, 0, 300, 180), "TrackGit - Clone",
28  B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
29 {
30  fClone = clone;
32 
33  fURL = new BTextControl(B_TRANSLATE("URL:"), "", NULL);
34  fPathBox = new PathBox("pathbox", dirPath.String(), "Path:");
35  BButton* fClone = new BButton("ok", B_TRANSLATE("Clone"),
36  new BMessage(kDoClone));
37  BButton* fCancel = new BButton("ok", B_TRANSLATE("Cancel"),
38  new BMessage(kCancel));
39 
40  BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
41  .SetInsets(10)
42  .Add(fURL)
43  .Add(fPathBox)
44  .AddGroup(B_HORIZONTAL, 0)
45  .AddGlue()
46  .Add(fCancel)
47  .Add(fClone)
48  .End();
49 
50  CenterOnScreen();
51  Show();
52 }
53 
54 
59 void
61 {
62  fProgressWindow->SetText(text.String());
63 }
64 
65 
70 void
71 CloneWindow::SetProgress(float progress)
72 {
73  fProgressWindow->SetProgress(progress);
74 }
75 
76 
81 void
83 {
84  switch (msg->what) {
85  case kDoClone:
87  fProgressWindow->CenterOnScreen();
88  fProgressWindow->Show();
89  fThreadId = fClone->DoClone(this, fURL->Text(), fPathBox->Path());
90  break;
91  case kCancel:
92  if (fThreadId)
93  pthread_cancel(fThreadId);
94  Quit();
95  break;
96  default:
97  BWindow::MessageReceived(msg);
98  }
99 }
100 
101 
107  :
108  BWindow(BRect(0, 0, 300, 150), "", B_MODAL_WINDOW,
109  B_NOT_CLOSABLE | B_NOT_RESIZABLE)
110 {
111  fCloneWindow = cloneWindow;
112  fTextView = new BTextView(BRect(0, 0, 280, 80), "_clone_",
113  BRect(0, 0, 280, 80), B_FOLLOW_LEFT_RIGHT);
114  fTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
115  fTextView->MakeEditable(false);
116  fTextView->MakeSelectable(false);
117  fTextView->SetWordWrap(true);
118  fTextView->SetText("Cloning" B_UTF8_ELLIPSIS "\nRepository");
119 
120  fProgressBar = new BStatusBar("progressBar");
121  fProgressBar->SetBarHeight(20);
122 
123  BButton* fCancel = new BButton("ok", "Cancel",
124  new BMessage(kCancel));
125 
126  BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
127  .SetInsets(10)
128  .Add(fTextView)
129  .Add(fProgressBar)
130  .AddGroup(B_HORIZONTAL, 0)
131  .AddGlue()
132  .Add(fCancel)
133  .End();
134 }
135 
136 
141 void
143 {
144  if (LockLooper()) {
145  fTextView->SetText(text);
146  UnlockLooper();
147  }
148 }
149 
150 
155 void
157 {
158  if (LockLooper()) {
159  fProgressBar->SetTo(progress);
160  UnlockLooper();
161  }
162 }
163 
164 
169 void
171 {
172  switch (msg->what) {
173  case kCancel:
174  fCloneWindow->PostMessage(kCancel);
175  Quit();
176  break;
177  default:
178  BWindow::MessageReceived(msg);
179  }
180 }
pthread_t fThreadId
The thread Id of clone thread.
Definition: CloneWindow.h:51
Header file of Clone window.
virtual void MessageReceived(BMessage *)
The handler to receive messages.
The Clone Progress Window class.
Definition: CloneWindow.h:63
BStatusBar * fProgressBar
The progress bar.
Definition: CloneWindow.h:77
virtual void Quit()
The function to Quit the window.
virtual void MessageReceived(BMessage *)
The handler to receive messages.
Definition: CloneWindow.cpp:82
BTextView * fTextView
The text view to show progress text.
Definition: CloneWindow.h:73
CloneWindow * fCloneWindow
The Clone Window pointer.
Definition: CloneWindow.h:69
void SetProgress(float)
Sets the progress value of the progress bar in progress window.
Definition: CloneWindow.cpp:71
BTextControl * fURL
The text control for url.
Definition: CloneWindow.h:38
CloneProgressWindow(CloneWindow *)
The CloneProgressWindow constructor.
void SetProgressText(BString)
Prints progress text to textview of window.
Definition: CloneWindow.cpp:60
void SetText(const char *)
This function sets texts of the textview within window.
CloneWindow(BString, BString, Clone *)
Constructor for CloneWindow.
Definition: CloneWindow.cpp:25
CloneProgressWindow * fProgressWindow
The progress window.
Definition: CloneWindow.h:34
PathBox * fPathBox
The text control for path.
Definition: CloneWindow.h:42
Clone * fClone
The clone command pointer.
Definition: CloneWindow.h:47
The Clone Window class.
Definition: CloneWindow.h:30
pthread_t DoClone(CloneWindow *, const char *, const char *)
Spawns a thread to clone.
Definition: Clone.cpp:213
Clone command Class.
Definition: Clone.h:46
The TrackGit Window class.
void SetProgress(float)
This function sets the value of progress bar.