@@ -32,11 +32,15 @@ const auto personalC = QLatin1String("personal");
32
32
const auto sharesIdC = QLatin1String(" a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668" );
33
33
}
34
34
35
- Space::Space (SpacesManager *spacesManager, const OpenAPI::OAIDrive &drive)
35
+ Space::Space (SpacesManager *spacesManager, const OpenAPI::OAIDrive &drive, const bool hasManyPersonalSpaces )
36
36
: QObject(spacesManager)
37
37
, _spaceManager(spacesManager)
38
38
, _image(new SpaceImage(this ))
39
+ , _hasManyPersonalSpaces(hasManyPersonalSpaces)
39
40
{
41
+ // todo future refactoring: get this setDrive out of the ctr since it potentially kicks off a job for the SpaceImage before the Space is fully constructed
42
+ // propose removing the drive arg from the ctr completely, and moving the call to setDrive to the spacesmanager such that any call to
43
+ // "new" space is immediately followed by setDrive.
40
44
setDrive (drive);
41
45
connect (_image, &SpaceImage::imageChanged, this , &Space::imageChanged);
42
46
}
@@ -48,63 +52,34 @@ OpenAPI::OAIDrive Space::drive() const
48
52
49
53
void Space::setDrive (const OpenAPI::OAIDrive &drive)
50
54
{
51
- _drive = drive;
52
- _image->update ();
53
- }
54
55
55
- SpaceImage::SpaceImage (Space *space)
56
- : QObject(space)
57
- , _space(space)
58
- {
59
- update ();
60
- }
56
+ // first config naturally has an empty drive - reality check that updated drives are always valid
57
+ Q_ASSERT (drive.isValid ());
61
58
62
- QIcon SpaceImage::image () const
63
- {
64
- if (_image.isNull ()) {
65
- return Resources::getCoreIcon (QStringLiteral (" space" ));
66
- }
67
- return _image;
68
- }
69
-
70
- QUrl SpaceImage::qmlImageUrl () const
71
- {
72
- if (!_image.isNull ()) {
73
- return QUrl (QStringLiteral (" image://space/%1/%2" ).arg (etag (), _space->id ()));
74
- } else {
75
- // invalid space id to display the placeholder
76
- return QUrl (QStringLiteral (" image://space/placeholder" ));
77
- }
78
- }
59
+ QString curTag = _drive.getRoot ().getETag ();
60
+ QString newTag = drive.getRoot ().getETag ();
61
+ Q_ASSERT (!newTag.isEmpty ());
62
+ // the tag should change when the space is edited on the server. I verified that it changes on space rename as well
63
+ // as on changing the space image so we may have further wrinkles if there is an error in logic server side, but for now
64
+ // we want to reduce updates to "only when something changed" else everything is auto-refreshed periodically (eg every 30s)
65
+ if (curTag == newTag)
66
+ return ;
79
67
80
- void SpaceImage::update ()
81
- {
82
- const auto &special = _space->drive ().getSpecial ();
83
- const auto img = std::find_if (special.cbegin (), special.cend (), [](const auto &it) { return it.getSpecialFolder ().getName () == QLatin1String (" image" ); });
84
- if (img != special.cend ()) {
85
- _url = QUrl (img->getWebDavUrl ());
86
- _etag = Utility::normalizeEtag (img->getETag ());
87
- auto job = _space->_spaceManager ->account ()->resourcesCache ()->makeGetJob (_url, {}, _space);
88
- QObject::connect (job, &SimpleNetworkJob::finishedSignal, _space, [job, this ] {
89
- if (job->httpStatusCode () == 200 ) {
90
- _image = job->asIcon ();
91
- Q_EMIT imageChanged ();
92
- }
93
- });
94
- job->start ();
95
- }
68
+ _drive = drive;
69
+ _image->update ();
96
70
}
97
71
98
72
QString Space::displayName () const
99
73
{
100
- auto hasManyPersonalSpaces = _spaceManager->account ()->capabilities ().spacesSupport ().enabled ;
101
- if (hasManyPersonalSpaces) {
74
+ if (_hasManyPersonalSpaces) {
102
75
return _drive.getName ();
103
76
}
104
77
78
+ // other systems like oCIS have one personal and one shared space and their names are hard coded
105
79
if (_drive.getDriveType () == personalC) {
106
80
return tr (" Personal" );
107
- } else if (_drive.getId () == sharesIdC) {
81
+ }
82
+ if (_drive.getId () == sharesIdC) {
108
83
// don't call it ShareJail
109
84
return tr (" Shares" );
110
85
}
@@ -141,3 +116,61 @@ QUrl Space::webdavUrl() const
141
116
{
142
117
return QUrl (_drive.getRoot ().getWebDavUrl ());
143
118
}
119
+
120
+ SpaceImage::SpaceImage (Space *space)
121
+ : QObject(space)
122
+ , _space(space)
123
+ {
124
+ }
125
+
126
+ QIcon SpaceImage::image () const
127
+ {
128
+ if (_image.isNull ()) {
129
+ return Resources::getCoreIcon (QStringLiteral (" space" ));
130
+ }
131
+ return _image;
132
+ }
133
+
134
+ QUrl SpaceImage::qmlImageUrl () const
135
+ {
136
+ if (!_image.isNull ()) {
137
+ return QUrl (QStringLiteral (" image://space/%1/%2" ).arg (etag (), _space->id ()));
138
+ } else {
139
+ // invalid space id to display the placeholder
140
+ return QUrl (QStringLiteral (" image://space/placeholder" ));
141
+ }
142
+ }
143
+
144
+ void SpaceImage::update ()
145
+ {
146
+ const auto &special = _space->drive ().getSpecial ();
147
+ const auto img = std::find_if (special.cbegin (), special.cend (), [](const auto &it) { return it.getSpecialFolder ().getName () == QLatin1String (" image" ); });
148
+ if (img != special.cend ())
149
+ {
150
+ // ssue 12057: verified the image etag does change when the space's icon has been updated via the web interface
151
+ // check the etag before updating the members and creating the job. This should eliminate *many* pointless resource jobs which
152
+ // will exacerbate whatever is making the app crash when the space tries to clean up it's child jobs and one is already gone
153
+ QString newEtag = Utility::normalizeEtag (img->getETag ());
154
+ if (_etag == newEtag)
155
+ return ;
156
+
157
+ _etag = newEtag;
158
+ _url = QUrl (img->getWebDavUrl ());
159
+ // issue 12057: I am leaving the space as the parent of the job just to avoid having confusion about "new" destructor crashes. At least
160
+ // we'll get any future crashes on the space still. I don't think that changing the parent is going to eliminate the associate crash - save
161
+ // this for a future refactoring
162
+ auto job = _space->_spaceManager ->account ()->resourcesCache ()->makeGetJob (_url, {}, _space);
163
+
164
+ // TODO: next problem = this routine is correctly run when the icon has changed on the server, but the icon in the gui does not get refreshed!
165
+ // The icon IS in the app cache, so it seems to have been brought back from the server correctly, but it is not shown until restart
166
+ // I did have a quick look at Resources::getCoreIcon - that is used in the SpaceImage::image function. Also sus is that I can't find any slot
167
+ // for the imageChanged signal but I think this may be connected in qml via the associated space image property.
168
+ QObject::connect (job, &SimpleNetworkJob::finishedSignal, _space, [job, this ] {
169
+ if (job->httpStatusCode () == 200 ) {
170
+ _image = job->asIcon ();
171
+ Q_EMIT imageChanged ();
172
+ }
173
+ });
174
+ job->start ();
175
+ }
176
+ }
0 commit comments